Type store

This commit is contained in:
Adria Navarro 2025-01-09 11:32:10 +01:00
parent 45ee157037
commit 96cee21792
1 changed files with 10 additions and 9 deletions

View File

@ -6,7 +6,7 @@ const DEFAULT_NOTIFICATION_TIMEOUT = 3000
const createNotificationStore = () => { const createNotificationStore = () => {
let block = false let block = false
const store = writable([]) const store = writable<{ id: string; message: string; count: number }[]>([])
const blockNotifications = (timeout = 1000) => { const blockNotifications = (timeout = 1000) => {
block = true block = true
@ -14,17 +14,18 @@ const createNotificationStore = () => {
} }
const send = ( const send = (
message, message: string,
type = "info", type = "info",
icon, icon: string,
autoDismiss = true, autoDismiss = true,
duration, duration: number,
count = 1 count = 1
) => { ) => {
if (block) { if (block) {
return return
} }
// @ts-expect-error
if (get(routeStore).queryParams?.peek) { if (get(routeStore).queryParams?.peek) {
window.parent.postMessage({ window.parent.postMessage({
type: "notification", type: "notification",
@ -66,7 +67,7 @@ const createNotificationStore = () => {
} }
} }
const dismiss = id => { const dismiss = (id: string) => {
store.update(state => { store.update(state => {
return state.filter(n => n.id !== id) return state.filter(n => n.id !== id)
}) })
@ -76,13 +77,13 @@ const createNotificationStore = () => {
subscribe: store.subscribe, subscribe: store.subscribe,
actions: { actions: {
send, send,
info: (msg, autoDismiss, duration) => info: (msg: string, autoDismiss: boolean, duration: number) =>
send(msg, "info", "Info", autoDismiss ?? true, duration), 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), 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), 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), send(msg, "error", "Alert", autoDismiss ?? false, duration),
blockNotifications, blockNotifications,
dismiss, dismiss,