diff --git a/ui/components/NotifyDropdown.vue b/ui/components/NotifyDropdown.vue new file mode 100644 index 00000000..8e977a18 --- /dev/null +++ b/ui/components/NotifyDropdown.vue @@ -0,0 +1,134 @@ + + + + + diff --git a/ui/composables/useNotification.ts b/ui/composables/useNotification.ts index dda3f462..62d2a79b 100644 --- a/ui/composables/useNotification.ts +++ b/ui/composables/useNotification.ts @@ -1,12 +1,23 @@ import { useStorage } from '@vueuse/core' import { POSITION, useToast } from "vue-toastification" -type notificationType = 'info' | 'success' | 'warning' | 'error' -type notificationOptions = { +export type notificationType = 'info' | 'success' | 'warning' | 'error' + +export interface Notification { + id: string; + message: string + level: notificationType + seen: boolean + created: Date +}; + +export interface notificationOptions { timeout?: number, force?: boolean, + store?: boolean, closeOnClick?: boolean, position?: POSITION + onClick?: (closeToast: Function) => void } const allowToast = useStorage('allow_toasts', true) @@ -15,11 +26,24 @@ const toastDismissOnClick = useStorage('toast_dismiss_on_click', true) const toast = useToast() function notify(type: notificationType, message: string, opts?: notificationOptions): void { - let force = opts?.force || false; + const notificationStore = useNotificationStore() + + let id: string = '' + const force = opts?.force || false; + const store = opts?.store || true; + + if (store && notificationStore) { + id = notificationStore.add(type, message, false) + } + if (false === allowToast.value && false === force) { return; } + if (false === document.hasFocus()) { + return; + } + if (!opts) { opts = {} } @@ -30,6 +54,14 @@ function notify(type: notificationType, message: string, opts?: notificationOpti opts.closeOnClick = toastDismissOnClick.value opts.position = toastPosition.value ?? POSITION.TOP_RIGHT + opts.onClick = (closeToast: Function) => { + if (opts?.closeOnClick !== false) { + closeToast() + } + if (notificationStore) { + notificationStore.markRead(id) + } + } switch (type) { case 'info': diff --git a/ui/layouts/default.vue b/ui/layouts/default.vue index 9319a463..ad43a523 100644 --- a/ui/layouts/default.vue +++ b/ui/layouts/default.vue @@ -86,6 +86,8 @@ + +