Skip to content

Commit 68958d1

Browse files
committed
feat(web): clear notifications indicator after opening sidebar
1 parent 7b105d1 commit 68958d1

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

web/components/Notifications/Indicator.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BellIcon, ExclamationTriangleIcon, ShieldExclamationIcon } from '@heroi
33
import { cn } from '~/components/shadcn/utils';
44
import { Importance, type OverviewQuery } from '~/composables/gql/graphql';
55
6-
const props = defineProps<{ overview?: OverviewQuery['notifications']['overview'] }>();
6+
const props = defineProps<{ overview?: OverviewQuery['notifications']['overview'], seen?: boolean }>();
77
88
const indicatorLevel = computed(() => {
99
if (!props.overview?.unread) {
@@ -42,12 +42,12 @@ const icon = computed<{ component: Component; color: string } | null>(() => {
4242
<div class="relative">
4343
<BellIcon class="w-6 h-6 text-header-text-primary" />
4444
<div
45-
v-if="indicatorLevel === 'UNREAD'"
45+
v-if="!seen && indicatorLevel === 'UNREAD'"
4646
class="absolute top-0 right-0 size-2.5 rounded-full border border-neutral-800 bg-unraid-green"
4747
/>
4848
<component
4949
:is="icon.component"
50-
v-else-if="icon && indicatorLevel"
50+
v-else-if="!seen && icon && indicatorLevel"
5151
:class="cn('absolute -top-1 -right-1 size-4 rounded-full', icon.color)"
5252
/>
5353
</div>

web/components/Notifications/Sidebar.vue

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,32 @@ const overview = computed(() => {
3939
}
4040
return result.value.notifications.overview;
4141
});
42+
43+
/** whether user has viewed their notifications */
44+
const hasSeenNotifications = ref(false);
45+
46+
// renews unseen state when new notifications arrive
47+
watch(
48+
() => overview.value?.unread,
49+
(newVal, oldVal) => {
50+
if (!newVal || !oldVal) return;
51+
if (newVal.total > oldVal.total) {
52+
hasSeenNotifications.value = false;
53+
}
54+
}
55+
);
56+
57+
const prepareToViewNotifications = () => {
58+
determineTeleportTarget();
59+
hasSeenNotifications.value = true;
60+
};
4261
</script>
4362

4463
<template>
4564
<Sheet>
46-
<SheetTrigger @click="determineTeleportTarget">
65+
<SheetTrigger @click="prepareToViewNotifications">
4766
<span class="sr-only">Notifications</span>
48-
<NotificationsIndicator :overview="overview" />
67+
<NotificationsIndicator :overview="overview" :seen="hasSeenNotifications" />
4968
</SheetTrigger>
5069
<SheetContent
5170
:to="teleportTarget"

0 commit comments

Comments
 (0)