Files
2026-05-26 22:46:00 +02:00

22 lines
869 B
TypeScript

// 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);
}