From c35c70e71ff378b6b877d0422ca66277f6e3f59a Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 23 Sep 2024 10:31:09 +0200 Subject: [PATCH] feat: do not load notifications while in the background --- frontend/src/components/notifications/Notifications.vue | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frontend/src/components/notifications/Notifications.vue b/frontend/src/components/notifications/Notifications.vue index def5d9bbd..07ac04293 100644 --- a/frontend/src/components/notifications/Notifications.vue +++ b/frontend/src/components/notifications/Notifications.vue @@ -124,15 +124,20 @@ let interval: ReturnType onMounted(() => { loadNotifications() document.addEventListener('click', hidePopup) + document.addEventListener('visibilitychange', loadNotifications) interval = setInterval(loadNotifications, LOAD_NOTIFICATIONS_INTERVAL) }) onUnmounted(() => { document.removeEventListener('click', hidePopup) + document.removeEventListener('visibilitychange', loadNotifications) clearInterval(interval) }) async function loadNotifications() { + if (document.visibilityState !== 'visible') { + return + } // We're recreating the notification service here to make sure it uses the latest api user token const notificationService = new NotificationService() allNotifications.value = await notificationService.getAll()