WIP: Staged all changes
This commit is contained in:
13
frontend/src/lib/toasts.js
Normal file
13
frontend/src/lib/toasts.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const toasts = writable([]);
|
||||
|
||||
export function addToast(message, type = 'info', duration = 3000) {
|
||||
const id = Math.random().toString(36).substr(2, 9);
|
||||
toasts.update(all => [...all, { id, message, type }]);
|
||||
setTimeout(() => removeToast(id), duration);
|
||||
}
|
||||
|
||||
function removeToast(id) {
|
||||
toasts.update(all => all.filter(t => t.id !== id));
|
||||
}
|
||||
Reference in New Issue
Block a user