trail save fix

This commit is contained in:
Christian Beutel
2025-02-14 13:22:20 +01:00
parent a2ad4a4800
commit bd8bae2ac9
43 changed files with 164 additions and 105 deletions

View File

@@ -0,0 +1,31 @@
import cryptoRandomString from "crypto-random-string";
export type Toast = {
id?: string;
type: "info" | "success" | "warning" | "error"
icon: string;
text: string;
}
class ToastStore {
toasts: Toast[] = $state([]);
}
export const toastStore = new ToastStore()
export function show_toast(newToast: Toast, duration: number = 3000) {
newToast.id = cryptoRandomString({ length: 15 })
toastStore.toasts.push(newToast);
setTimeout(() => {
closeToast(newToast)
}, duration);
}
export function closeToast(toast: Toast) {
const toastIndex = toastStore.toasts.findIndex(t => t.id == toast.id)
console.log(toastIndex);
toastStore.toasts.splice(toastIndex, 1)
}