From bc810ee2dd0c673f66b19eb85081e49a2cb627f5 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Mon, 1 Sep 2025 22:55:35 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Adds=20defaults=20to=20notificat?= =?UTF-8?q?ion=20service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/components/toasts/notifications.ts | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/app/src/lib/components/toasts/notifications.ts b/app/src/lib/components/toasts/notifications.ts index 6659a1c..3131abb 100644 --- a/app/src/lib/components/toasts/notifications.ts +++ b/app/src/lib/components/toasts/notifications.ts @@ -1,42 +1,42 @@ -import { writable, derived, type Writable } from 'svelte/store'; +import { writable, derived, type Writable } from 'svelte/store' -type StateType = 'info' | 'success' | 'warning' | 'error'; +type StateType = 'info' | 'success' | 'warning' | 'error' type State = { - id: string; - type: StateType; - message: string; -}; + id: string + type: StateType + message: string +} function createNotificationStore() { - const state: State[] = []; - const notifications = writable(state); - const { subscribe } = notifications; + const state: State[] = [] + const notifications = writable(state) + const { subscribe } = notifications - function send(message: string, type: StateType = 'info', timeout: number) { - const id = generateId(); - setTimeout(() => { - notifications.update((state) => { - return state.filter((n) => n.id !== id); - }); - }, timeout); - notifications.update((state) => { - return [...state, { id, type, message }]; - }); - } + function send(message: string, type: StateType = 'info', timeout: number) { + const id = generateId() + setTimeout(() => { + notifications.update(state => { + return state.filter(n => n.id !== id) + }) + }, timeout) + notifications.update(state => { + return [...state, { id, type, message }] + }) + } - 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) - }; + return { + subscribe, + send, + error: (msg: string, timeout: number = 4000) => send(msg, 'error', timeout), + warning: (msg: string, timeout: number = 4000) => send(msg, 'warning', timeout), + info: (msg: string, timeout: number = 4000) => send(msg, 'info', timeout), + success: (msg: string, timeout: number = 4000) => send(msg, 'success', timeout) + } } function generateId() { - return '_' + Math.random().toString(36).substr(2, 9); + return '_' + Math.random().toString(36).substr(2, 9) } -export const notifications = createNotificationStore(); +export const notifications = createNotificationStore()