Initial commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
// Event helpers split out of WatchQueueProvider.tsx so that the
|
||||
// provider file's only exports are the Component and the `useXxx`
|
||||
// hook — the shape Next.js Fast Refresh needs to swap in place
|
||||
// instead of forcing a full reload.
|
||||
|
||||
const REMOVE_EVENT = "pinkudex:queue-remove";
|
||||
|
||||
export function dispatchQueueRemove(ids: number | number[]) {
|
||||
if (typeof window === "undefined") return;
|
||||
const arr = Array.isArray(ids) ? ids : [ids];
|
||||
window.dispatchEvent(new CustomEvent(REMOVE_EVENT, { detail: arr }));
|
||||
}
|
||||
|
||||
export function subscribeQueueRemove(cb: (ids: number[]) => void): () => void {
|
||||
function onRemove(e: Event) {
|
||||
const detail = (e as CustomEvent<number[]>).detail;
|
||||
if (Array.isArray(detail) && detail.length > 0) cb(detail);
|
||||
}
|
||||
window.addEventListener(REMOVE_EVENT, onRemove);
|
||||
return () => window.removeEventListener(REMOVE_EVENT, onRemove);
|
||||
}
|
||||
Reference in New Issue
Block a user