{
const settings = useSettings()
const toast = useToast()
+ const laptop = useLaptop()
+ const hasNewNotification = ref()
const notifications = ref([])
+ const shouldBeShown = computed(() => {
+ if (laptop.isOpen) return false
+ if (settings.doNotDisturb) return false
+ if (!hasNewNotification.value) return false
+
+ return true
+ })
+
const show = (data: Omit) => {
notifications.value.push({
summary: data.summary,
@@ -18,6 +30,11 @@ export const useNotifications = defineStore('notifications', () => {
if (settings.doNotDisturb) return
+ if (hasNewNotification.value) clearTimeout(hasNewNotification.value)
+ hasNewNotification.value = setTimeout(() => {
+ hasNewNotification.value = undefined
+ }, 4000)
+
toast.add({
//@ts-ignore
severity: 'custom',
@@ -43,7 +60,14 @@ export const useNotifications = defineStore('notifications', () => {
show,
clear,
close,
+ shouldBeShown,
notifications,
hasNotifications
}
})
+
+useNuiEvent('newNotification', (data: Notification) => {
+ const notifications = useNotifications()
+
+ notifications.show(data)
+})
diff --git a/web/src/stores/settings.store.ts b/web/src/stores/settings.store.ts
index 98db36d..d7961e8 100644
--- a/web/src/stores/settings.store.ts
+++ b/web/src/stores/settings.store.ts
@@ -3,6 +3,8 @@ import { computed, ref, watch } from 'vue'
import { useDevelopment } from './development.store'
import { useNuiEvent } from '../composables/useNuiEvent'
import type { UpdateProfileEvent, UserSettings, UserSettingsEvent } from '../types/settings.types'
+import { useApi } from '../composables/useApi'
+import { watchDebounced } from '@vueuse/core'
export const useSettings = defineStore('settings', () => {
const development = useDevelopment()
@@ -47,6 +49,22 @@ export const useSettings = defineStore('settings', () => {
handleDarkModeChange()
})
+ watchDebounced(
+ doNotDisturb,
+ (newValue) => {
+ useApi(
+ 'setDoNotDisturb',
+ {
+ method: 'POST',
+ body: JSON.stringify({ doNotDisturb: newValue })
+ },
+ undefined,
+ undefined
+ )
+ },
+ { debounce: 1000 }
+ )
+
return {
forApps,
username,