@@ -21,6 +21,12 @@ import {
2121 TabsTrigger ,
2222} from ' @unraid/ui' ;
2323
24+ import type {
25+ NotificationAddedSubSubscription ,
26+ NotificationOverviewSubSubscription ,
27+ OverviewQuery ,
28+ } from ' ~/composables/gql/graphql' ;
29+
2430import { useTrackLatestSeenNotification } from ' ~/composables/api/use-notifications' ;
2531import { useFragment } from ' ~/composables/gql' ;
2632import { Importance , NotificationType } from ' ~/composables/gql/graphql' ;
@@ -61,16 +67,39 @@ const confirmAndDeleteArchives = async () => {
6167const { result, subscribeToMore } = useQuery (notificationsOverview );
6268subscribeToMore ({
6369 document: notificationOverviewSubscription ,
64- updateQuery : (prev , { subscriptionData }) => {
70+ updateQuery : (
71+ prev : OverviewQuery ,
72+ { subscriptionData }: { subscriptionData: { data: NotificationOverviewSubSubscription } }
73+ ) => {
6574 const snapshot = structuredClone (prev );
66- snapshot .notifications .overview = subscriptionData .data .notificationsOverview ;
75+ const subData = subscriptionData .data .notificationsOverview ;
76+ const unreadFragment = subData .unread [' $fragmentRefs' ]?.NotificationCountFragmentFragment ;
77+ const archiveFragment = subData .archive [' $fragmentRefs' ]?.NotificationCountFragmentFragment ;
78+
79+ if (! unreadFragment || ! archiveFragment ) return snapshot ;
80+
81+ snapshot .notifications .overview = {
82+ __typename: ' NotificationOverview' ,
83+ unread: {
84+ __typename: ' NotificationCounts' ,
85+ info: unreadFragment .info ,
86+ warning: unreadFragment .warning ,
87+ alert: unreadFragment .alert ,
88+ total: unreadFragment .total ,
89+ },
90+ archive: {
91+ __typename: ' NotificationCounts' ,
92+ total: archiveFragment .total ,
93+ },
94+ };
95+
6796 return snapshot ;
6897 },
6998});
7099const { latestNotificationTimestamp, haveSeenNotifications } = useTrackLatestSeenNotification ();
71100const { onResult : onNotificationAdded } = useSubscription (notificationAddedSubscription );
72101
73- onNotificationAdded (({ data }) => {
102+ onNotificationAdded (({ data }: { data : NotificationAddedSubSubscription | null } ) => {
74103 if (! data ) return ;
75104 const notif = useFragment (NOTIFICATION_FRAGMENT , data .notificationAdded );
76105 if (notif .type !== NotificationType .Unread ) return ;
0 commit comments