feat: use timeout instead of interval for pulling
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Dominik Pschenitschni 2022-11-22 19:01:40 +01:00
parent 9109c25d3d
commit c0ca76fccf
Signed by: dpschen
GPG Key ID: B257AC0149F43A77
1 changed files with 8 additions and 4 deletions

View File

@ -19,7 +19,7 @@ export const useNotificationStore = defineStore('notification', () => {
})
const hasUnreadNotifications = computed(() => unreadNotifications.value > 0)
let interval: ReturnType<typeof setInterval>
let timeout: ReturnType<typeof setTimeout>
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<INotification | undefined> {