#41 add toasts and use for success and error

This commit is contained in:
2024-07-30 21:30:10 +02:00
parent 205913b4a4
commit c642996777
5 changed files with 70 additions and 33 deletions

27
view/src/lib/toast.ts Normal file
View File

@@ -0,0 +1,27 @@
import { writable } from "svelte/store";
type Type = 'success' | 'info' | 'warning' | 'error';
type Toast = {
message: string;
type: Type;
}
const toastStore = writable<Toast[]>([]);
const addToast = (message: string, type: Type) => {
const newToast = { message, type };
toastStore.update((toasts) => {
return [...toasts, newToast];
});
setTimeout(() => {
toastStore.update((toasts) => toasts.filter((t) => t !== newToast));
}, 5000);
}
export { toastStore, addToast, };
export type { Toast }