Skip to content

Commit

Permalink
Fixes and template updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauteri committed Dec 29, 2024
1 parent 9a4796c commit 2550f85
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build/blocks/rsvp-response-v2/view.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => 'f6fdfb423dc5e30364f7', 'type' => 'module');
<?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => '4b7fabd304a7121f40fd', 'type' => 'module');
2 changes: 1 addition & 1 deletion build/blocks/rsvp-response-v2/view.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/blocks/rsvp-template/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element'), 'version' => 'eca4e4f2d79566fb0674');
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'beae3ad928c6ab05eb6d');
2 changes: 1 addition & 1 deletion build/blocks/rsvp-template/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/blocks/rsvp-v2/view.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => 'dc3813b00dfe0de045a8', 'type' => 'module');
<?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => 'd14816eac12e45b51699', 'type' => 'module');
2 changes: 1 addition & 1 deletion build/blocks/rsvp-v2/view.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions build/vendors-node_modules_leaflet_dist_leaflet_css-rtl.css
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,3 @@ svg.leaflet-image-layer.leaflet-interactive path {
}
}

lor-adjust: exact;
}
}

32 changes: 26 additions & 6 deletions src/blocks/rsvp-response-v2/view.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
/**
* WordPress dependencies.
*/
import { store, getElement } from '@wordpress/interactivity';
import { store, getElement, getContext } from '@wordpress/interactivity';

/**
* Internal dependencies.
*/
import { getFromGlobal } from '../../helpers/globals';

store('gatherpress', {
const { state, callbacks } = store('gatherpress', {
state: {
posts: {},
},
callbacks: {
processRsvpDropdown() {
callbacks.initPostContext();

// Get the current element.
const element = getElement();
const context = getContext();
const postId = context?.postId || 0;

if (element && element.ref) {
// Check if the `data-label` attribute is already set.
Expand All @@ -29,7 +36,6 @@ store('gatherpress', {
const parentElement = element.ref.parentElement;
const classList = parentElement?.classList || [];
const dataLabel = element.ref.getAttribute('data-label');
const responses = getFromGlobal('eventDetails.responses');
const activeElement = element.ref.classList.contains(
'gatherpress--is-disabled'
);
Expand All @@ -41,11 +47,11 @@ store('gatherpress', {
let count = 0;

if (classList.contains('gatherpress--rsvp-attending')) {
count = responses?.attending?.count || 0;
count = state.posts[postId]?.eventResponses?.attending || 0;
} else if (classList.contains('gatherpress--rsvp-waiting-list')) {
count = responses?.waiting_list?.count || 0;
count = state.posts[postId]?.eventResponses?.waitingList || 0;
} else if (classList.contains('gatherpress--rsvp-not-attending')) {
count = responses?.not_attending?.count || 0;
count = state.posts[postId]?.eventResponses?.notAttending || 0;
}

// Replace %d in the data-label with the count and update the text content.
Expand All @@ -65,5 +71,19 @@ store('gatherpress', {
}
}
},
initPostContext() {
const context = getContext();
const responses = getFromGlobal('eventDetails.responses');

if (!state.posts[context?.postId]) {
state.posts[context?.postId] = {
eventResponses: {
attending: responses?.attending?.count || 0,
waitingList: responses?.waiting_list?.count || 0,
notAttending: responses?.not_attending?.count || 0,
},
};
}
},
},
});
16 changes: 15 additions & 1 deletion src/blocks/rsvp-template/template.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
/**
* WordPress dependencies.
*/
import { __ } from '@wordpress/i18n';

const TEMPLATE = [
[
'core/group',
{},
{
style: {
spacing: {
blockGap: 0,
},
},
},
[
[
'core/avatar',
Expand All @@ -13,6 +24,9 @@ const TEMPLATE = [
[
'core/comment-author-name',
{
metadata: {
name: __('Display Name', 'gatherpress'),
},
textAlign: 'center',
style: {
spacing: {
Expand Down
12 changes: 11 additions & 1 deletion src/blocks/rsvp-v2/view.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies.
*/
import { store, getElement } from '@wordpress/interactivity';
import { store, getElement, getContext } from '@wordpress/interactivity';

/**
* Internal dependencies.
Expand All @@ -17,6 +17,8 @@ const { state, actions } = store('gatherpress', {
updateRsvp() {
let status = 'not_attending';
const element = getElement();
const context = getContext();
const postId = context?.postId || 0;

if (['not_attending', 'no_status'].includes(state.rsvpStatus)) {
status = 'attending';
Expand Down Expand Up @@ -44,6 +46,14 @@ const { state, actions } = store('gatherpress', {
state.activePostId = res.event_id;
state.rsvpResponseStatus = res.status;
state.rsvpStatus = res.status;
state.posts[postId] = {
...state.posts[postId],
eventResponses: {
attending: res.responses.attending.count,
waitingList: res.responses.waiting_list.count,
notAttending: res.responses.not_attending.count,
},
};
actions.closeModal(null, element.ref);
}
})
Expand Down

0 comments on commit 2550f85

Please sign in to comment.