11import type { Notification , Task , User } from '@roll-stack/database'
22
3- type NotificationWithEntities = Notification & {
4- task : Task | null
3+ type TaskWithPerformer = Task & {
4+ performer : User | null
55}
66
7- type NotificationWithTask = Notification & {
8- task : ( Task & {
9- performer : User
10- } )
7+ type NotificationWithEntities = Notification & {
8+ task : TaskWithPerformer | null
9+ author : User
1110}
1211
1312export const useNotificationStore = defineStore ( 'notification' , ( ) => {
1413 const notifications = ref < NotificationWithEntities [ ] > ( [ ] )
1514
16- const interval = ref < NodeJS . Timeout | undefined > ( undefined )
1715 const toastContext = useToast ( )
1816
1917 async function update ( ) {
@@ -36,13 +34,13 @@ export const useNotificationStore = defineStore('notification', () => {
3634 }
3735 }
3836
39- function showCompletedTaskToast ( notification : NotificationWithTask ) {
37+ function _showCompletedTaskToast ( notification : NotificationWithEntities ) {
4038 toastContext . add ( {
4139 id : notification . id ,
4240 title : notification . title ,
43- description : notification . description ,
41+ description : notification . description ?? '' ,
4442 avatar : {
45- src : notification . task . performer . avatarUrl ?? undefined ,
43+ src : notification . task ? .performer ? .avatarUrl ?? undefined ,
4644 alt : '' ,
4745 } ,
4846 color : 'info' ,
@@ -97,26 +95,18 @@ export const useNotificationStore = defineStore('notification', () => {
9795 // }, 3000)
9896 }
9997
100- watch ( notifications , ( ) => {
101- for ( const notification of notifications . value ) {
102- // already shown?
103- if ( toastContext . toasts . value . find ( ( toast ) => toast . id === notification . id ) ) {
104- continue
105- }
106-
107- if ( notification . type === 'task_completed' ) {
108- showCompletedTaskToast ( notification as NotificationWithTask )
109- }
110- }
111- } )
112-
113- onMounted ( ( ) => {
114- interval . value = setInterval ( ( ) => update ( ) , 30000 )
115- } )
98+ // watch(notifications, () => {
99+ // for (const notification of notifications.value) {
100+ // // already shown?
101+ // if (toastContext.toasts.value.find((toast) => toast.id === notification.id)) {
102+ // continue
103+ // }
116104
117- onUnmounted ( ( ) => {
118- clearInterval ( interval . value )
119- } )
105+ // if (notification.type === 'task_completed') {
106+ // showCompletedTaskToast(notification)
107+ // }
108+ // }
109+ // })
120110
121111 return {
122112 notifications,
0 commit comments