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 = () => {
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,