From 1de18c9685a0657939f1e575eed6e7cc01c1f77c Mon Sep 17 00:00:00 2001 From: isUnknown Date: Tue, 17 Dec 2024 14:21:33 +0100 Subject: [PATCH] #34 - fix notification count --- .../site/plugins/notifications/user-methods/read.php | 1 + src/components/Menu.vue | 2 +- src/views/Notifications.vue | 12 +++++++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/public/site/plugins/notifications/user-methods/read.php b/public/site/plugins/notifications/user-methods/read.php index 4de14df..cb61db0 100644 --- a/public/site/plugins/notifications/user-methods/read.php +++ b/public/site/plugins/notifications/user-methods/read.php @@ -8,6 +8,7 @@ return function($notificationId) { $newNotification = null; foreach ($notifications as $key => $notification) { + if (!isset($notification['id'])) continue; if ($notification['id'] === $notificationId) { $notifications[$key]['isRead'] = true; $newNotification = $notifications[$key]; diff --git a/src/components/Menu.vue b/src/components/Menu.vue index 3b40c06..8139b17 100644 --- a/src/components/Menu.vue +++ b/src/components/Menu.vue @@ -116,7 +116,7 @@ const { page } = storeToRefs(usePageStore()); const unreadNotificationsCount = computed(() => { if (!user.value) return undefined; - const count = user.value.notifications.map( + const count = user.value.notifications.filter( (notification) => notification.isRead ).length; if (count === 0) return undefined; diff --git a/src/views/Notifications.vue b/src/views/Notifications.vue index e6cc4b1..a359917 100644 --- a/src/views/Notifications.vue +++ b/src/views/Notifications.vue @@ -174,12 +174,14 @@ function readAll() { function read(notification) { if (!notification.isRead) { - api.readNotification(notification.id).then((res) => { - console.log(res); - // router.push(toPath(notification.location.href)); - }); + console.log(notification); + api + .readNotification(notification.id) + .then((res) => { + router.push(toPath(notification.location.href)); + }) + .catch((err) => console.log(err)); } - router.push(toPath(notification.location.href)); } function toPath(string) {