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.
|
// 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.
|
// There is a similar listener in showplanner/index.tsx to actually reload the show plan.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.addEventListener(
|
function reloadListener(event: MessageEvent) {
|
||||||
"message",
|
|
||||||
(event) => {
|
|
||||||
if (!event.origin.includes("ury.org.uk")) {
|
if (!event.origin.includes("ury.org.uk")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.data === "reload_showplan") {
|
if (event.data === "reload_showplan") {
|
||||||
props.close();
|
props.close();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
false
|
|
||||||
);
|
window.addEventListener("message", reloadListener);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("message", reloadListener);
|
||||||
|
};
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<Modal isOpen={props.isOpen} onRequestClose={props.close}>
|
<Modal isOpen={props.isOpen} onRequestClose={props.close}>
|
||||||
|
|
|
@ -374,9 +374,7 @@ const Showplanner: React.FC<{ timeslotId: number }> = function({ timeslotId }) {
|
||||||
// Add support for reloading the show plan from the iFrames.
|
// Add support for reloading the show plan from the iFrames.
|
||||||
// There is a similar listener in showplanner/ImporterModal.tsx to handle closing the iframe.
|
// There is a similar listener in showplanner/ImporterModal.tsx to handle closing the iframe.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.addEventListener(
|
function reloadListener(event: MessageEvent) {
|
||||||
"message",
|
|
||||||
(event) => {
|
|
||||||
if (!event.origin.includes("ury.org.uk")) {
|
if (!event.origin.includes("ury.org.uk")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -384,10 +382,14 @@ const Showplanner: React.FC<{ timeslotId: number }> = function({ timeslotId }) {
|
||||||
session.currentTimeslot !== null &&
|
session.currentTimeslot !== null &&
|
||||||
dispatch(getShowplan(session.currentTimeslot.timeslot_id));
|
dispatch(getShowplan(session.currentTimeslot.timeslot_id));
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
false
|
|
||||||
);
|
window.addEventListener("message", reloadListener);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("message", reloadListener);
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
if (showplan === null) {
|
if (showplan === null) {
|
||||||
return (
|
return (
|
||||||
<LoadingDialogue
|
<LoadingDialogue
|
||||||
|
|
Loading…
Reference in a new issue