Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make nonexistent MessageChannel come back
  • Loading branch information
regalijan committed Oct 27, 2023
1 parent f218390 commit 5c785a8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions app/routes/mod-queue.tsx
Expand Up @@ -119,7 +119,9 @@ export default function () {
[] as { element: ReactNode; id: string }[],
);
const [before, setBefore] = useState(Date.now());
const [messageChannel] = useState(null as MessageChannel | null);
const [messageChannel, setMessageChannel] = useState(
null as MessageChannel | null,
);
const toast = useToast();

for (const type of pageProps.entry_types)
Expand All @@ -130,13 +132,15 @@ export default function () {
);

useEffect(() => {
if (!messageChannel) return;

messageChannel.port1.onmessage = function (ev) {
const { data }: { data: string } = ev;

setEntries([...entries].filter((entry) => entry.id !== data));
};
if (!messageChannel) {
setMessageChannel(new MessageChannel());
} else {
messageChannel.port1.onmessage = function (ev) {
const { data }: { data: string } = ev;

setEntries([...entries].filter((entry) => entry.id !== data));
};
}
}, [messageChannel]);

async function updateQueue(
Expand Down

0 comments on commit 5c785a8

Please sign in to comment.