feat: use timeout instead of interval for pulling
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
9109c25d3d
commit
c0ca76fccf
|
@ -19,7 +19,7 @@ export const useNotificationStore = defineStore('notification', () => {
|
||||||
})
|
})
|
||||||
const hasUnreadNotifications = computed(() => unreadNotifications.value > 0)
|
const hasUnreadNotifications = computed(() => unreadNotifications.value > 0)
|
||||||
|
|
||||||
let interval: ReturnType<typeof setInterval>
|
let timeout: ReturnType<typeof setTimeout>
|
||||||
|
|
||||||
const notificationService = new NotificationService()
|
const notificationService = new NotificationService()
|
||||||
|
|
||||||
|
@ -27,14 +27,18 @@ export const useNotificationStore = defineStore('notification', () => {
|
||||||
allNotifications.value = await notificationService.getAll() as INotification[]
|
allNotifications.value = await notificationService.getAll() as INotification[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function pullNotifications() {
|
||||||
|
await loadNotifications()
|
||||||
|
timeout = setTimeout(pullNotifications, NOTIFICATIONS_PULL_INTERVAL)
|
||||||
|
}
|
||||||
|
|
||||||
function startNotificationPulling() {
|
function startNotificationPulling() {
|
||||||
loadNotifications()
|
pullNotifications()
|
||||||
interval = setInterval(loadNotifications, NOTIFICATIONS_PULL_INTERVAL)
|
|
||||||
return stopNotificationPulling
|
return stopNotificationPulling
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopNotificationPulling() {
|
function stopNotificationPulling() {
|
||||||
clearInterval(interval)
|
clearTimeout(timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function markNotificationAsRead(notificationItem: INotification): Promise<INotification | undefined> {
|
async function markNotificationAsRead(notificationItem: INotification): Promise<INotification | undefined> {
|
||||||
|
|
Reference in New Issue