This repository has been archived on 2025-08-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
web-app-template/view/src/lib/toast.ts
Tim 325b085b54
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 32s
#41 add toasts and use for success and error
2024-07-30 21:30:10 +02:00

28 lines
513 B
TypeScript

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 }