Skip to content

Commit e17f994

Browse files
committed
feat(web): pulse indicator when new notifications are received
1 parent ed26254 commit e17f994

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

web/components/Notifications/Indicator.vue

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import {
77
ExclamationTriangleIcon,
88
ShieldExclamationIcon,
99
} from "@heroicons/vue/24/solid";
10-
import { cn } from "../shadcn/utils";
10+
import { cn } from '~/components/shadcn/utils'
11+
import { onWatcherCleanup } from "vue";
1112
1213
const { result } = useQuery(unreadOverview, null, {
13-
pollInterval: 1_000, // 1 second
14+
pollInterval: 2_000, // 2 seconds
1415
});
1516
1617
const overview = computed(() => {
@@ -51,6 +52,22 @@ const icon = computed<{ component: Component; color: string } | null>(() => {
5152
}
5253
return null;
5354
});
55+
56+
/** whether new notifications ocurred */
57+
const hasNewNotifications = ref(false);
58+
// watch for new notifications, set a temporary indicator when they're reveived
59+
watch(overview, (newVal, oldVal) => {
60+
if (!newVal || !oldVal) {
61+
return;
62+
}
63+
hasNewNotifications.value = newVal.total > oldVal.total;
64+
// lifetime of 'new notification' state
65+
const msToLive = 30_000;
66+
const timeout = setTimeout(() => {
67+
hasNewNotifications.value = false;
68+
}, msToLive);
69+
onWatcherCleanup(() => clearTimeout(timeout));
70+
});
5471
</script>
5572

5673
<template>
@@ -68,7 +85,7 @@ const icon = computed<{ component: Component; color: string } | null>(() => {
6885
"
6986
/>
7087
<div
71-
v-if="indicatorLevel === Importance.Alert"
88+
v-if="hasNewNotifications || indicatorLevel === Importance.Alert"
7289
class="absolute top-0 right-0 size-2.5 rounded-full bg-unraid-red animate-ping"
7390
/>
7491
</div>

0 commit comments

Comments
 (0)