28 lines
717 B
TypeScript
28 lines
717 B
TypeScript
|
|
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]);
|
||
|
|
}
|
||
|
|
);
|
||
|
|
|
||
|
|
export const dismissToastAtom = atom<null, [string], void>(
|
||
|
|
null,
|
||
|
|
(get, set, id) => set(baseAtom, get(baseAtom).filter((t) => t.id !== id))
|
||
|
|
);
|