2026-06-04 21:32:37 -04:00
|
|
|
import { atom } from 'jotai';
|
|
|
|
|
|
|
|
|
|
export type ToastNotif = {
|
|
|
|
|
id: string;
|
|
|
|
|
avatarUrl?: string;
|
|
|
|
|
displayName: string;
|
|
|
|
|
body: string;
|
|
|
|
|
roomName: string;
|
|
|
|
|
roomId: string;
|
|
|
|
|
hashPath?: string; // overrides window.location.hash navigation when set
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const baseAtom = atom<ToastNotif[]>([]);
|
|
|
|
|
|
|
|
|
|
// Write-only setter used in ClientNonUIFeatures
|
|
|
|
|
export const toastQueueAtom = atom<ToastNotif[], [ToastNotif | null], void>(
|
|
|
|
|
(get) => get(baseAtom),
|
|
|
|
|
(get, set, notif) => {
|
|
|
|
|
if (notif === null) return; // no-op guard
|
|
|
|
|
set(baseAtom, [...get(baseAtom), notif]);
|
2026-06-04 22:01:54 -04:00
|
|
|
},
|
2026-06-04 21:32:37 -04:00
|
|
|
);
|
|
|
|
|
|
2026-06-04 22:01:54 -04:00
|
|
|
export const dismissToastAtom = atom<null, [string], void>(null, (get, set, id) =>
|
|
|
|
|
set(
|
|
|
|
|
baseAtom,
|
|
|
|
|
get(baseAtom).filter((t) => t.id !== id),
|
|
|
|
|
),
|
2026-06-04 21:32:37 -04:00
|
|
|
);
|