From 421c7a908ba44a273d41ec09ae9be2b823c3cd23 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Sat, 8 Jun 2024 18:02:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Removes=20duplicated=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/lib/components/notifications.ts | 52 ------------------------- 1 file changed, 52 deletions(-) delete mode 100644 app/src/lib/components/notifications.ts diff --git a/app/src/lib/components/notifications.ts b/app/src/lib/components/notifications.ts deleted file mode 100644 index 9ac6964..0000000 --- a/app/src/lib/components/notifications.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { writable, derived } from 'svelte/store'; - -type State = { - id: string; - type: string; - message: string; - timeout: number; -}; - -function createNotificationStore() { - const state: State[] = []; - const _notifications = writable(state); - - function send(message: string, type = 'info', timeout: number) { - _notifications.update((state) => { - return [...state, { id: id(), type, message, timeout }]; - }); - } - - let timers = []; - - const notifications = derived(_notifications, ($_notifications, set) => { - set($_notifications); - if ($_notifications.length > 0) { - const timer = setTimeout(() => { - _notifications.update((state) => { - state.shift(); - return state; - }); - }, $_notifications[0].timeout); - return () => { - clearTimeout(timer); - }; - } - }); - const { subscribe } = notifications; - - return { - subscribe, - send, - error: (msg: string, timeout: number) => send(msg, 'error', timeout), - warning: (msg: string, timeout: number) => send(msg, 'warning', timeout), - info: (msg: string, timeout: number) => send(msg, 'info', timeout), - success: (msg: string, timeout: number) => send(msg, 'success', timeout) - }; -} - -function id() { - return '_' + Math.random().toString(36).substr(2, 9); -} - -export const notifications = createNotificationStore();