From 5bb1c8e87bdd1904786cd52791363b4d6c93c83b Mon Sep 17 00:00:00 2001 From: Mike Auteri Date: Thu, 9 Jan 2025 19:26:33 -0500 Subject: [PATCH] Fix RSVP Guest Count in Query. --- build/blocks/rsvp-guest-count-display/block.json | 3 ++- .../blocks/rsvp-guest-count-display/index.asset.php | 2 +- build/blocks/rsvp-guest-count-display/index.js | 4 ++-- src/blocks/rsvp-guest-count-display/block.json | 2 +- src/blocks/rsvp-guest-count-display/edit.js | 13 +++---------- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/build/blocks/rsvp-guest-count-display/block.json b/build/blocks/rsvp-guest-count-display/block.json index 76cd87dd1..7c54428d4 100644 --- a/build/blocks/rsvp-guest-count-display/block.json +++ b/build/blocks/rsvp-guest-count-display/block.json @@ -14,7 +14,8 @@ "example": {}, "attributes": {}, "usesContext": [ - "commentId" + "commentId", + "gatherpress/rsvpResponses" ], "supports": { "align": [ diff --git a/build/blocks/rsvp-guest-count-display/index.asset.php b/build/blocks/rsvp-guest-count-display/index.asset.php index c49bdbf26..90030d48e 100644 --- a/build/blocks/rsvp-guest-count-display/index.asset.php +++ b/build/blocks/rsvp-guest-count-display/index.asset.php @@ -1 +1 @@ - array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-data', 'wp-i18n'), 'version' => '6e170f08233749ccc34b'); + array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-data', 'wp-i18n'), 'version' => 'fa8b89d30ccf6aa5d10e'); diff --git a/build/blocks/rsvp-guest-count-display/index.js b/build/blocks/rsvp-guest-count-display/index.js index 2aeeb3e14..55a0ea95a 100644 --- a/build/blocks/rsvp-guest-count-display/index.js +++ b/build/blocks/rsvp-guest-count-display/index.js @@ -1,2 +1,2 @@ -(()=>{"use strict";var e,t={6306:()=>{const e=window.wp.blocks,t=window.wp.i18n,r=window.wp.blockEditor,s=window.wp.data,i=window.ReactJSXRuntime,n=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"gatherpress/rsvp-guest-count-display","version":"1.0.0","title":"RSVP Guest Count Display","description":"Displays the number of guests associated with a member\'s RSVP.","category":"gatherpress","ancestor":["gatherpress/rsvp-v2","gatherpress/rsvp-template"],"icon":"yes","example":{},"attributes":{},"usesContext":["commentId"],"supports":{"align":["left","center","right"],"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true},"color":{"text":true,"background":true},"html":false,"interactivity":true},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","render":"file:./render.php"}');(0,e.registerBlockType)(n,{edit:({context:e})=>{const{commentId:n}=e;let o=1;if(n){const e=function(){if("object"==typeof GatherPress)return"eventDetails.responses.attending.responses".split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}().find((e=>e.commentId===n));e&&(o=e.guests)}const a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta")?.gatherpress_max_guest_limit),[]),p=(0,r.useBlockProps)({className:0!==a||n?"":"gatherpress--is-not-visible"});if(0===o)return(0,i.jsx)("div",{...p});const l=(0,t.sprintf)(/* translators: %d: Number of guests. Singular and plural forms are used for 1 guest and multiple guests, respectively. */ /* translators: %d: Number of guests. Singular and plural forms are used for 1 guest and multiple guests, respectively. */ -(0,t._n)("+%d guest","+%d guests",o,"gatherpress"),o);return(0,i.jsx)("div",{...p,children:l})},save:()=>null})}},r={};function s(e){var i=r[e];if(void 0!==i)return i.exports;var n=r[e]={exports:{}};return t[e](n,n.exports,s),n.exports}s.m=t,e=[],s.O=(t,r,i,n)=>{if(!r){var o=1/0;for(c=0;c=n)&&Object.keys(s.O).every((e=>s.O[e](r[p])))?r.splice(p--,1):(a=!1,n0&&e[c-1][2]>n;c--)e[c]=e[c-1];e[c]=[r,i,n]},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={498:0,702:0};s.O.j=t=>0===e[t];var t=(t,r)=>{var i,n,[o,a,p]=r,l=0;if(o.some((t=>0!==e[t]))){for(i in a)s.o(a,i)&&(s.m[i]=a[i]);if(p)var c=p(s)}for(t&&t(r);ls(6306)));i=s.O(i)})(); \ No newline at end of file +(()=>{"use strict";var e,t={8928:()=>{const e=window.wp.blocks,t=window.wp.i18n,s=window.wp.blockEditor,r=window.wp.data,i=window.ReactJSXRuntime,n=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"gatherpress/rsvp-guest-count-display","version":"1.0.0","title":"RSVP Guest Count Display","description":"Displays the number of guests associated with a member\'s RSVP.","category":"gatherpress","ancestor":["gatherpress/rsvp-v2","gatherpress/rsvp-template"],"icon":"yes","example":{},"attributes":{},"usesContext":["commentId","gatherpress/rsvpResponses"],"supports":{"align":["left","center","right"],"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true},"color":{"text":true,"background":true},"html":false,"interactivity":true},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","render":"file:./render.php"}');(0,e.registerBlockType)(n,{edit:({context:e})=>{var n;const{commentId:o}=e,a=null!==(n=e?.["gatherpress/rsvpResponses"])&&void 0!==n?n:null;let p=1;if(o&&a){const e=a.attending.responses.find((e=>e.commentId===o));e&&(p=e.guests)}const l=(0,r.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta")?.gatherpress_max_guest_limit),[]),c=(0,s.useBlockProps)({className:0!==l||o?"":"gatherpress--is-not-visible"});if(0===p)return(0,i.jsx)("div",{...c});const u=(0,t.sprintf)(/* translators: %d: Number of guests. Singular and plural forms are used for 1 guest and multiple guests, respectively. */ /* translators: %d: Number of guests. Singular and plural forms are used for 1 guest and multiple guests, respectively. */ +(0,t._n)("+%d guest","+%d guests",p,"gatherpress"),p);return(0,i.jsx)("div",{...c,children:u})},save:()=>null})}},s={};function r(e){var i=s[e];if(void 0!==i)return i.exports;var n=s[e]={exports:{}};return t[e](n,n.exports,r),n.exports}r.m=t,e=[],r.O=(t,s,i,n)=>{if(!s){var o=1/0;for(c=0;c=n)&&Object.keys(r.O).every((e=>r.O[e](s[p])))?s.splice(p--,1):(a=!1,n0&&e[c-1][2]>n;c--)e[c]=e[c-1];e[c]=[s,i,n]},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={498:0,702:0};r.O.j=t=>0===e[t];var t=(t,s)=>{var i,n,[o,a,p]=s,l=0;if(o.some((t=>0!==e[t]))){for(i in a)r.o(a,i)&&(r.m[i]=a[i]);if(p)var c=p(r)}for(t&&t(s);lr(8928)));i=r.O(i)})(); \ No newline at end of file diff --git a/src/blocks/rsvp-guest-count-display/block.json b/src/blocks/rsvp-guest-count-display/block.json index 4d019ad12..15abae0b6 100644 --- a/src/blocks/rsvp-guest-count-display/block.json +++ b/src/blocks/rsvp-guest-count-display/block.json @@ -10,7 +10,7 @@ "icon": "yes", "example": {}, "attributes": {}, - "usesContext": [ "commentId" ], + "usesContext": [ "commentId", "gatherpress/rsvpResponses" ], "supports": { "align": [ "left", "center", "right" ], "spacing": { diff --git a/src/blocks/rsvp-guest-count-display/edit.js b/src/blocks/rsvp-guest-count-display/edit.js index 4cf87eda3..e8202e2fd 100644 --- a/src/blocks/rsvp-guest-count-display/edit.js +++ b/src/blocks/rsvp-guest-count-display/edit.js @@ -5,11 +5,6 @@ import { _n, sprintf } from '@wordpress/i18n'; import { useBlockProps } from '@wordpress/block-editor'; import { useSelect } from '@wordpress/data'; -/** - * Internal dependencies. - */ -import { getFromGlobal } from '../../helpers/globals'; - /** * Edit function for the RSVP Guest Count Display Block. * @@ -25,15 +20,13 @@ import { getFromGlobal } from '../../helpers/globals'; */ const Edit = ({ context }) => { const { commentId } = context; + const rsvpResponses = context?.['gatherpress/rsvpResponses'] ?? null; // Example guest count. let guestCount = 1; - if (commentId) { - const responses = getFromGlobal( - 'eventDetails.responses.attending.responses' - ); - const matchedResponse = responses.find( + if (commentId && rsvpResponses) { + const matchedResponse = rsvpResponses.attending.responses.find( (response) => response.commentId === commentId );