From 0cf26819cec2dd56a4820fc912db9783765a321d Mon Sep 17 00:00:00 2001 From: isUnknown Date: Tue, 17 Dec 2024 14:16:00 +0100 Subject: [PATCH] #34 - fix console error --- src/components/Menu.vue | 23 +++++++++++++---------- src/views/Notifications.vue | 3 ++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/Menu.vue b/src/components/Menu.vue index c27d76e..3b40c06 100644 --- a/src/components/Menu.vue +++ b/src/components/Menu.vue @@ -39,7 +39,9 @@ :key="mainItem.path" :class="{ active: isCurrent(mainItem), disabled: mainItem.disabled }" :data-count=" - mainItem.title === 'Notifications' ? notificationCount() : undefined + mainItem.title === 'Notifications' + ? unreadNotificationsCount + : undefined " > import { storeToRefs } from "pinia"; -import { ref } from "vue"; +import { computed, ref } from "vue"; import { useProjectsStore } from "../stores/projects"; import { useRoute } from "vue-router"; import { useUserStore } from "../stores/user"; @@ -112,6 +114,15 @@ const { user } = storeToRefs(useUserStore()); const { currentProjects, archivedProjects } = storeToRefs(useProjectsStore()); const { page } = storeToRefs(usePageStore()); +const unreadNotificationsCount = computed(() => { + if (!user.value) return undefined; + const count = user.value.notifications.map( + (notification) => notification.isRead + ).length; + if (count === 0) return undefined; + return count; +}); + const mainItems = [ { title: "Home", @@ -158,14 +169,6 @@ function collapse() { isExpanded.value = false; } } - -function notificationCount() { - const count = user.value.notifications.map( - (notification) => notification.isRead - ).length; - if (count === 0) return undefined; - return count; -}