Merge pull request #158 from UniversityRadioYork/mstratford-save-tidies

This commit is contained in:
Marks Polakovs 2020-11-02 18:55:23 +00:00 committed by GitHub
commit 1e5aae0b51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 26 deletions

View file

@ -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) => {
function reloadListener(event: MessageEvent) {
if (!event.origin.includes("ury.org.uk")) {
return;
}
if (event.data === "reload_showplan") {
props.close();
}
},
false
);
}
window.addEventListener("message", reloadListener);
return () => {
window.removeEventListener("message", reloadListener);
};
});
return (
<Modal isOpen={props.isOpen} onRequestClose={props.close}>

View file

@ -389,9 +389,7 @@ 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) => {
function reloadListener(event: MessageEvent) {
if (!event.origin.includes("ury.org.uk")) {
return;
}
@ -399,10 +397,14 @@ const Showplanner: React.FC<{ timeslotId: number }> = function({ timeslotId }) {
session.currentTimeslot !== null &&
dispatch(getShowplan(session.currentTimeslot.timeslot_id));
}
},
false
);
});
}
window.addEventListener("message", reloadListener);
return () => {
window.removeEventListener("message", reloadListener);
};
}, [dispatch, session.currentTimeslot]);
if (showplan === null) {
return (
<LoadingDialogue