mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-10-13 10:37:16 +02:00
31 lines
788 B
JavaScript
31 lines
788 B
JavaScript
import { writable } from "svelte/store";
|
|
|
|
/**
|
|
* @type {import("svelte/store").Writable<{id: number, text: string, type:string}[]>}
|
|
*/
|
|
export const toasts = writable([]);
|
|
|
|
let nextID = 0;
|
|
|
|
/**
|
|
* add a toast
|
|
*
|
|
* @param {string} text
|
|
* @param {"Success"|"Info"|"Warning"|"Error"} type
|
|
*/
|
|
export const addToast = (text, type, visibilityMS = 5000) => {
|
|
const t = { id: nextID++, text, type }
|
|
toasts.update((toasts) => [...toasts, t]);
|
|
// remove the toast after the specified time
|
|
setTimeout(() => {
|
|
toasts.update((toasts) => toasts.filter((toast) => toast.id !== t.id));
|
|
}, visibilityMS);
|
|
}
|
|
|
|
/**
|
|
* Removes a toast
|
|
* @param {number} id
|
|
*/
|
|
export const removeToast = (id) => {
|
|
toasts.update((toasts) => toasts.filter((toast) => toast.id !== id));
|
|
} |