diff --git a/src/stores/notifications.ts b/src/stores/notifications.ts index 1b1f204ee..0f62e510a 100644 --- a/src/stores/notifications.ts +++ b/src/stores/notifications.ts @@ -19,7 +19,7 @@ export const useNotificationStore = defineStore('notification', () => { }) const hasUnreadNotifications = computed(() => unreadNotifications.value > 0) - let interval: ReturnType + let timeout: ReturnType const notificationService = new NotificationService() @@ -27,14 +27,18 @@ export const useNotificationStore = defineStore('notification', () => { allNotifications.value = await notificationService.getAll() as INotification[] } + async function pullNotifications() { + await loadNotifications() + timeout = setTimeout(pullNotifications, NOTIFICATIONS_PULL_INTERVAL) + } + function startNotificationPulling() { - loadNotifications() - interval = setInterval(loadNotifications, NOTIFICATIONS_PULL_INTERVAL) + pullNotifications() return stopNotificationPulling } function stopNotificationPulling() { - clearInterval(interval) + clearTimeout(timeout) } async function markNotificationAsRead(notificationItem: INotification): Promise {