Merged in bugfix/VBV-261-deactivate-notifications-when-logged-out (pull request #29)
VBV-261 start & stop notification polling based on user state * Start & stop notification polling based on user state * Improve readability Approved-by: Christian Cueni
This commit is contained in:
parent
2d580cad18
commit
d686173b31
|
|
@ -1,7 +1,9 @@
|
||||||
import { itGet } from "@/fetchHelpers";
|
import { itGet } from "@/fetchHelpers";
|
||||||
|
import { useUserStore } from "@/stores/user";
|
||||||
import type { Notification } from "@/types";
|
import type { Notification } from "@/types";
|
||||||
|
import log from "loglevel";
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { ref } from "vue";
|
import { ref, watch } from "vue";
|
||||||
|
|
||||||
type NotificationListData = {
|
type NotificationListData = {
|
||||||
all_count: number;
|
all_count: number;
|
||||||
|
|
@ -29,8 +31,18 @@ export const useNotificationsStore = defineStore("notifications", () => {
|
||||||
hasUnread.value = data.unread_count !== 0;
|
hasUnread.value = data.unread_count !== 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateUnreadCount();
|
const userStore = useUserStore();
|
||||||
setInterval(async () => await updateUnreadCount(), 30000);
|
let timerHandle: number | null = null;
|
||||||
|
watch(userStore, () => {
|
||||||
|
if (userStore.loggedIn && timerHandle === null) {
|
||||||
|
log.debug("Notification polling started");
|
||||||
|
updateUnreadCount();
|
||||||
|
timerHandle = setInterval(async () => await updateUnreadCount(), 30000);
|
||||||
|
} else if (!userStore.loggedIn) {
|
||||||
|
log.debug("Notification polling stopped");
|
||||||
|
timerHandle = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return { loadNotifications, hasUnread, allCount };
|
return { loadNotifications, hasUnread, allCount };
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue