Only reload showplan once, don't add multiple listeners.
This commit is contained in:
parent
f87a971e68
commit
fb5b17aab4
2 changed files with 28 additions and 25 deletions
|
@ -14,18 +14,19 @@ export function ImporterModal(props: ImporterProps) {
|
|||
// Add support for closing the modal when the importer wants to reload the show plan.
|
||||
// There is a similar listener in showplanner/index.tsx to actually reload the show plan.
|
||||
useEffect(() => {
|
||||
window.addEventListener(
|
||||
"message",
|
||||
(event) => {
|
||||
if (!event.origin.includes("ury.org.uk")) {
|
||||
return;
|
||||
}
|
||||
if (event.data === "reload_showplan") {
|
||||
props.close();
|
||||
}
|
||||
},
|
||||
false
|
||||
);
|
||||
function reloadListener(event: MessageEvent) {
|
||||
if (!event.origin.includes("ury.org.uk")) {
|
||||
return;
|
||||
}
|
||||
if (event.data === "reload_showplan") {
|
||||
props.close();
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("message", reloadListener);
|
||||
return () => {
|
||||
window.removeEventListener("message", reloadListener);
|
||||
};
|
||||
});
|
||||
return (
|
||||
<Modal isOpen={props.isOpen} onRequestClose={props.close}>
|
||||
|
|
|
@ -374,20 +374,22 @@ const Showplanner: React.FC<{ timeslotId: number }> = function({ timeslotId }) {
|
|||
// Add support for reloading the show plan from the iFrames.
|
||||
// There is a similar listener in showplanner/ImporterModal.tsx to handle closing the iframe.
|
||||
useEffect(() => {
|
||||
window.addEventListener(
|
||||
"message",
|
||||
(event) => {
|
||||
if (!event.origin.includes("ury.org.uk")) {
|
||||
return;
|
||||
}
|
||||
if (event.data === "reload_showplan") {
|
||||
session.currentTimeslot !== null &&
|
||||
dispatch(getShowplan(session.currentTimeslot.timeslot_id));
|
||||
}
|
||||
},
|
||||
false
|
||||
);
|
||||
function reloadListener(event: MessageEvent) {
|
||||
if (!event.origin.includes("ury.org.uk")) {
|
||||
return;
|
||||
}
|
||||
if (event.data === "reload_showplan") {
|
||||
session.currentTimeslot !== null &&
|
||||
dispatch(getShowplan(session.currentTimeslot.timeslot_id));
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("message", reloadListener);
|
||||
return () => {
|
||||
window.removeEventListener("message", reloadListener);
|
||||
};
|
||||
});
|
||||
|
||||
if (showplan === null) {
|
||||
return (
|
||||
<LoadingDialogue
|
||||
|
|
Loading…
Reference in a new issue