Prevent notifications in client apps from being automatically dismissed

This commit is contained in:
Andrew Kingston 2022-02-07 15:25:03 +00:00
parent fe495345f8
commit 85b6943853
3 changed files with 19 additions and 7 deletions

View File

@ -19,6 +19,8 @@
type={$notificationStore.type}
message={$notificationStore.message}
icon={$notificationStore.icon}
dismissable={$notificationStore.dismissable}
on:dismiss={notificationStore.actions.dismiss}
/>
</div>
{/key}

View File

@ -25,8 +25,8 @@
}
const proxyNotification = event => {
const { message, type, icon } = event.detail
notificationStore.actions.send(message, type, icon)
const { message, type, icon, autoDismiss } = event.detail
notificationStore.actions.send(message, type, icon, autoDismiss)
}
const proxyStateUpdate = event => {

View File

@ -19,7 +19,7 @@ const createNotificationStore = () => {
setTimeout(() => (block = false), timeout)
}
const send = (message, type = "info", icon) => {
const send = (message, type = "info", icon, autoDismiss = true) => {
if (block) {
return
}
@ -32,6 +32,7 @@ const createNotificationStore = () => {
message,
type,
icon,
autoDismiss,
},
})
return
@ -42,12 +43,20 @@ const createNotificationStore = () => {
type,
message,
icon,
dismissable: !autoDismiss,
delay: get(store) != null,
})
clearTimeout(timeout)
timeout = setTimeout(() => {
store.set(null)
}, NOTIFICATION_TIMEOUT)
if (autoDismiss) {
timeout = setTimeout(() => {
store.set(null)
}, NOTIFICATION_TIMEOUT)
}
}
const dismiss = () => {
clearTimeout(timeout)
store.set(null)
}
return {
@ -57,8 +66,9 @@ const createNotificationStore = () => {
info: msg => send(msg, "info", "Info"),
success: msg => send(msg, "success", "CheckmarkCircle"),
warning: msg => send(msg, "warning", "Alert"),
error: msg => send(msg, "error", "Alert"),
error: msg => send(msg, "error", "Alert", false),
blockNotifications,
dismiss,
},
}
}