blob: 454461bd5bb6809402e3ed758eb305b8d980c8ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import { writable } from "svelte/store";
export interface Toast {
color?: string | undefined;
title?: string | undefined;
message?: string | undefined;
}
export const toastList = writable<Toast[]>([]);
export function addToast(toast: Toast) {
toast ??= { color: "red", title: "Error", message: "An error occurred" };
toast.color ??= "red";
toast.title ??= "Error";
toast.message ??= "An error occurred";
toastList.update((list) => [...list, toast]);
setTimeout(() => {
toastList.update((list) => list.filter((t) => t !== toast));
}, 5000);
}
|