diff --git a/build/editor.asset.php b/build/editor.asset.php index a7bf37658..1913af654 100644 --- a/build/editor.asset.php +++ b/build/editor.asset.php @@ -1 +1 @@ - array('moment', 'react-jsx-runtime', 'wp-blocks', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => 'bc15603abbcb9b06567f'); + array('moment', 'react-jsx-runtime', 'wp-blocks', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '1e28ca063435d44e0985'); diff --git a/build/editor.js b/build/editor.js index ed72f5b10..d3834240a 100644 --- a/build/editor.js +++ b/build/editor.js @@ -1 +1 @@ -(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.domReady;var n=e.n(t);const i=window.wp.data,a=window.moment;var r=e.n(a);const s=window.wp.i18n;function d(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}function o(e,t){if("object"!=typeof GatherPress)return;const n=e.split("."),i=n.pop();n.reduce(((e,t)=>{var n;return null!==(n=e[t])&&void 0!==n?n:e[t]={}}),GatherPress)[i]=t}window.wp.element,window.wp.date,window.ReactJSXRuntime;const m="YYYY-MM-DDTHH:mm:ss",c=r().tz(p()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(m),T=r().tz(c,p()).add(2,"hours").format(m);function p(e=d("eventDetails.dateTime.timezone")){return r().tz.zone(e)?e:(0,s.__)("GMT","gatherpress")}const l=window.wp.blocks,u={dateTimeStart:d("eventDetails.dateTime.datetime_start")?d("eventDetails.dateTime.datetime_start"):c,dateTimeEnd:d("eventDetails.dateTime.datetime_end")?d("eventDetails.dateTime.datetime_end"):T,timezone:d("eventDetails.dateTime.timezone")},E={setDateTimeStart:e=>(o("eventDetails.dateTime.datetime_start",e),{type:"SET_DATETIME_START",dateTimeStart:e}),setDateTimeEnd:e=>(o("eventDetails.dateTime.datetime_end",e),{type:"SET_DATETIME_END",dateTimeEnd:e}),setTimezone:e=>(o("eventDetails.dateTime.timezone",e),{type:"SET_TIMEZONE",timezone:e})},g=(0,i.createReduxStore)("gatherpress/datetime",{reducer:(e=u,t)=>{switch(t.type){case"SET_DATETIME_START":return{...e,dateTimeStart:t.dateTimeStart};case"SET_DATETIME_END":return{...e,dateTimeEnd:t.dateTimeEnd};case"SET_TIMEZONE":return{...e,timezone:t.timezone};default:return e}},actions:E,selectors:{getDateTimeStart:e=>e.dateTimeStart,getDateTimeEnd:e=>e.dateTimeEnd,getTimezone:e=>e.timezone}});(0,i.register)(g),n()((()=>{const e=(0,i.select)("core/edit-post");if(!e)return;const t=(0,i.dispatch)("core/edit-post");e.isEditorSidebarOpened()?(t.openGeneralSidebar("edit-post/document"),t.toggleEditorPanelOpened("gatherpress-event-settings/gatherpress-event-settings")):(t.openGeneralSidebar(),t.toggleEditorPanelOpened("gatherpress-event-settings/gatherpress-event-settings")),function(){const e="gatherpress_event_past",t=(0,i.dispatch)("core/notices");t.removeNotice(e),function(){const e=r().tz(d("eventDetails.dateTime.datetime_end"),p());return"gatherpress_event"===(0,i.select)("core/editor")?.getCurrentPostType()&&r().tz(p()).valueOf()>e.valueOf()}()&&t.createNotice("warning",(0,s.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}()})),n()((()=>{Object.keys(d("misc.unregisterBlocks")).forEach((e=>{const t=d("misc.unregisterBlocks")[e];t&&void 0!==(0,l.getBlockType)(t)&&(0,l.unregisterBlockType)(t)}))}))})(); \ No newline at end of file +(()=>{"use strict";var e={n:t=>{var s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},d:(t,s)=>{for(var i in s)e.o(s,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:s[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.domReady;var s=e.n(t);const i=window.wp.data,n=window.moment;var r=e.n(n);const a=window.wp.i18n;function o(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}function d(e,t){if("object"!=typeof GatherPress)return;const s=e.split("."),i=s.pop();s.reduce(((e,t)=>{var s;return null!==(s=e[t])&&void 0!==s?s:e[t]={}}),GatherPress)[i]=t}window.wp.element,window.wp.date,window.ReactJSXRuntime;const c="YYYY-MM-DDTHH:mm:ss",m=r().tz(T()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(c),p=r().tz(m,T()).add(2,"hours").format(c);function T(e=o("eventDetails.dateTime.timezone")){return r().tz.zone(e)?e:(0,a.__)("GMT","gatherpress")}function l(){const e=r().tz(o("eventDetails.dateTime.datetime_end"),T());return"gatherpress_event"===(0,i.select)("core/editor")?.getCurrentPostType()&&r().tz(T()).valueOf()>e.valueOf()}let u=!1;function g(){const e="gatherpress_event_communication",t=(0,i.dispatch)("core/notices"),s=(0,i.select)("core/editor").isSavingPost(),n=(0,i.select)("core/editor").isAutosavingPost();"publish"!==(0,i.select)("core/editor").getEditedPostAttribute("status")||"gatherpress_event"!==(0,i.select)("core/editor")?.getCurrentPostType()||!s||n||l()||u||(u=!0,t.removeNotice(e),t.createNotice("success",(0,a.__)("Send an event update to members via email?","gatherpress"),{id:e,isDismissible:!0,actions:[{onClick:()=>{((e,t="")=>{for(const[s,i]of Object.entries(e)){let e=s;t&&(e+="_"+String(t));const n=new CustomEvent(e,{detail:i});dispatchEvent(n)}})({setOpen:!0})},label:(0,a.__)("Compose Message","gatherpress")}]})),s||(u=!1)}const v=window.wp.blocks,E={dateTimeStart:o("eventDetails.dateTime.datetime_start")?o("eventDetails.dateTime.datetime_start"):m,dateTimeEnd:o("eventDetails.dateTime.datetime_end")?o("eventDetails.dateTime.datetime_end"):p,timezone:o("eventDetails.dateTime.timezone")},_={setDateTimeStart:e=>(d("eventDetails.dateTime.datetime_start",e),{type:"SET_DATETIME_START",dateTimeStart:e}),setDateTimeEnd:e=>(d("eventDetails.dateTime.datetime_end",e),{type:"SET_DATETIME_END",dateTimeEnd:e}),setTimezone:e=>(d("eventDetails.dateTime.timezone",e),{type:"SET_TIMEZONE",timezone:e})},h=(0,i.createReduxStore)("gatherpress/datetime",{reducer:(e=E,t)=>{switch(t.type){case"SET_DATETIME_START":return{...e,dateTimeStart:t.dateTimeStart};case"SET_DATETIME_END":return{...e,dateTimeEnd:t.dateTimeEnd};case"SET_TIMEZONE":return{...e,timezone:t.timezone};default:return e}},actions:_,selectors:{getDateTimeStart:e=>e.dateTimeStart,getDateTimeEnd:e=>e.dateTimeEnd,getTimezone:e=>e.timezone}});(0,i.register)(h),s()((()=>{const e=(0,i.select)("core/edit-post");if(!e)return;const t=(0,i.dispatch)("core/edit-post");e.isEditorSidebarOpened()?(t.openGeneralSidebar("edit-post/document"),t.toggleEditorPanelOpened("gatherpress-event-settings/gatherpress-event-settings")):(t.openGeneralSidebar(),t.toggleEditorPanelOpened("gatherpress-event-settings/gatherpress-event-settings")),(0,i.subscribe)(g),function(){const e="gatherpress_event_past",t=(0,i.dispatch)("core/notices");t.removeNotice(e),l()&&t.createNotice("warning",(0,a.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}()})),s()((()=>{Object.keys(o("misc.unregisterBlocks")).forEach((e=>{const t=o("misc.unregisterBlocks")[e];t&&void 0!==(0,v.getBlockType)(t)&&(0,v.unregisterBlockType)(t)}))}))})(); \ No newline at end of file diff --git a/src/editor.js b/src/editor.js index a8c7b2499..18d2517be 100644 --- a/src/editor.js +++ b/src/editor.js @@ -2,8 +2,8 @@ * WordPress dependencies. */ import domReady from '@wordpress/dom-ready'; -import { dispatch, select } from '@wordpress/data'; -import { hasEventPastNotice } from './helpers/event'; +import { dispatch, select, subscribe } from '@wordpress/data'; +import { hasEventPastNotice, triggerEventCommunication } from './helpers/event'; import { getBlockType, unregisterBlockType } from '@wordpress/blocks'; import './stores'; @@ -53,7 +53,8 @@ domReady(() => { ); } - // Display a notice for past events using the 'hasEventPastNotice' function. + subscribe(triggerEventCommunication); + hasEventPastNotice(); }); diff --git a/src/helpers/event.js b/src/helpers/event.js index 6c92187f8..0158d7ae3 100644 --- a/src/helpers/event.js +++ b/src/helpers/event.js @@ -80,6 +80,13 @@ export function hasEventPastNotice() { } } +/** + * Flag to prevent multiple event communication notices. + * + * @type {boolean} + */ +let isEventCommunicationNoticeCreated = false; + /** * Trigger communication notice for event updates. * @@ -94,13 +101,25 @@ export function hasEventPastNotice() { export function triggerEventCommunication() { const id = 'gatherpress_event_communication'; const notices = dispatch('core/notices'); + const isSavingPost = select('core/editor').isSavingPost(); + const isAutosavingPost = select('core/editor').isAutosavingPost(); - notices.removeNotice(id); - + // Only proceed if a save is in progress and it's not an autosave. if ( 'publish' === select('core/editor').getEditedPostAttribute('status') && - !hasEventPast() + isEventPostType() && + isSavingPost && + !isAutosavingPost && + !hasEventPast() && + !isEventCommunicationNoticeCreated ) { + // Mark notice as created. + isEventCommunicationNoticeCreated = true; + + // Remove any previous notices with the same ID. + notices.removeNotice(id); + + // Create a new notice with an action. notices.createNotice( 'success', __('Send an event update to members via email?', 'gatherpress'), @@ -120,4 +139,9 @@ export function triggerEventCommunication() { } ); } + + // Reset the flag after the save operation completes. + if (!isSavingPost) { + isEventCommunicationNoticeCreated = false; + } }