diff options
Diffstat (limited to 'src/lib/Notification/store.ts')
| -rw-r--r-- | src/lib/Notification/store.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/lib/Notification/store.ts b/src/lib/Notification/store.ts new file mode 100644 index 00000000..0cb4cf96 --- /dev/null +++ b/src/lib/Notification/store.ts @@ -0,0 +1,32 @@ +import { writable } from 'svelte/store'; + +export interface Notification { + id: string; + heading: string; + description?: string; + duration?: number; +} + +function createNotificationStore() { + const { subscribe, update } = writable<Notification[]>([]); + + return { + subscribe, + add: (notification: Omit<Notification, 'id'>) => { + const id = crypto.randomUUID(); + + update((notifications) => [...notifications, { ...notification, id }]); + + return id; + }, + remove: (id: string) => { + update((notifications) => notifications.filter((n) => n.id !== id)); + } + }; +} + +export const notifications = createNotificationStore(); + +export function addNotification(notification: Omit<Notification, 'id'>) { + return notifications.add(notification); +} |