From 96cee21792413d638191e4a6872bf5e388d1786a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 9 Jan 2025 11:32:10 +0100 Subject: [PATCH] Type store --- packages/client/src/stores/notification.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/client/src/stores/notification.ts b/packages/client/src/stores/notification.ts index 054117aaba..6f5fcc9ef4 100644 --- a/packages/client/src/stores/notification.ts +++ b/packages/client/src/stores/notification.ts @@ -6,7 +6,7 @@ const DEFAULT_NOTIFICATION_TIMEOUT = 3000 const createNotificationStore = () => { let block = false - const store = writable([]) + const store = writable<{ id: string; message: string; count: number }[]>([]) const blockNotifications = (timeout = 1000) => { block = true @@ -14,17 +14,18 @@ const createNotificationStore = () => { } const send = ( - message, + message: string, type = "info", - icon, + icon: string, autoDismiss = true, - duration, + duration: number, count = 1 ) => { if (block) { return } + // @ts-expect-error if (get(routeStore).queryParams?.peek) { window.parent.postMessage({ type: "notification", @@ -66,7 +67,7 @@ const createNotificationStore = () => { } } - const dismiss = id => { + const dismiss = (id: string) => { store.update(state => { return state.filter(n => n.id !== id) }) @@ -76,13 +77,13 @@ const createNotificationStore = () => { subscribe: store.subscribe, actions: { send, - info: (msg, autoDismiss, duration) => + info: (msg: string, autoDismiss: boolean, duration: number) => send(msg, "info", "Info", autoDismiss ?? true, duration), - success: (msg, autoDismiss, duration) => + success: (msg: string, autoDismiss: boolean, duration: number) => send(msg, "success", "CheckmarkCircle", autoDismiss ?? true, duration), - warning: (msg, autoDismiss, duration) => + warning: (msg: string, autoDismiss: boolean, duration: number) => send(msg, "warning", "Alert", autoDismiss ?? true, duration), - error: (msg, autoDismiss, duration) => + error: (msg: string, autoDismiss: boolean, duration: number) => send(msg, "error", "Alert", autoDismiss ?? false, duration), blockNotifications, dismiss,