feat: Display notification count in sidebar inbox item (#12324)

This commit is contained in:
Sivin Varghese
2025-09-01 15:55:09 +05:30
committed by GitHub
parent c53e750be0
commit d68ac25187
4 changed files with 26 additions and 11 deletions

View File

@@ -128,7 +128,7 @@ const menuItems = computed(() => {
to: accountScopedRoute('inbox_view'), to: accountScopedRoute('inbox_view'),
activeOn: ['inbox_view', 'inbox_view_conversation'], activeOn: ['inbox_view', 'inbox_view_conversation'],
getterKeys: { getterKeys: {
badge: 'notifications/getHasUnreadNotifications', count: 'notifications/getUnreadCount',
}, },
}, },
{ {

View File

@@ -1,4 +1,5 @@
<script setup> <script setup>
import { computed } from 'vue';
import { useMapGetter } from 'dashboard/composables/store.js'; import { useMapGetter } from 'dashboard/composables/store.js';
import Icon from 'next/icon/Icon.vue'; import Icon from 'next/icon/Icon.vue';
@@ -16,12 +17,16 @@ const props = defineProps({
const emit = defineEmits(['toggle']); const emit = defineEmits(['toggle']);
const showBadge = useMapGetter(props.getterKeys.badge); const showBadge = useMapGetter(props.getterKeys.badge);
const dynamicCount = useMapGetter(props.getterKeys.count);
const count = computed(() =>
dynamicCount.value > 99 ? '99+' : dynamicCount.value
);
</script> </script>
<template> <template>
<component <component
:is="to ? 'router-link' : 'div'" :is="to ? 'router-link' : 'div'"
class="flex items-center gap-2 px-2 py-1.5 rounded-lg h-8" class="flex items-center gap-2 px-2 py-1.5 rounded-lg h-8 min-w-0"
role="button" role="button"
draggable="false" draggable="false"
:to="to" :to="to"
@@ -40,9 +45,21 @@ const showBadge = useMapGetter(props.getterKeys.badge);
class="size-2 -top-px ltr:-right-px rtl:-left-px bg-n-brand absolute rounded-full border border-n-solid-2" class="size-2 -top-px ltr:-right-px rtl:-left-px bg-n-brand absolute rounded-full border border-n-solid-2"
/> />
</div> </div>
<span class="text-sm font-medium leading-5 flex-grow"> <div class="flex items-center gap-1.5 flex-grow min-w-0">
{{ label }} <span class="text-sm font-medium leading-5 truncate">
</span> {{ label }}
</span>
<span
v-if="dynamicCount && !expandable"
class="rounded-md capitalize text-xs leading-5 font-medium text-center outline outline-1 px-1 flex-shrink-0"
:class="{
'text-n-blue-text outline-n-slate-6': isActive,
'text-n-slate-11 outline-n-strong': !isActive,
}"
>
{{ count }}
</span>
</div>
<span <span
v-if="expandable" v-if="expandable"
v-show="isExpanded" v-show="isExpanded"

View File

@@ -94,12 +94,7 @@ const loadMoreNotifications = () => {
const markNotificationAsRead = async notificationItem => { const markNotificationAsRead = async notificationItem => {
useTrack(INBOX_EVENTS.MARK_NOTIFICATION_AS_READ); useTrack(INBOX_EVENTS.MARK_NOTIFICATION_AS_READ);
const { const { id, primaryActorId, primaryActorType } = notificationItem;
id,
primary_actor_id: primaryActorId,
primary_actor_type: primaryActorType,
} = notificationItem;
try { try {
await store.dispatch('notifications/read', { await store.dispatch('notifications/read', {
id, id,

View File

@@ -38,4 +38,7 @@ export const getters = {
getHasUnreadNotifications: $state => { getHasUnreadNotifications: $state => {
return $state.meta.unreadCount > 0; return $state.meta.unreadCount > 0;
}, },
getUnreadCount: $state => {
return $state.meta.unreadCount;
},
}; };