@@ -69,12 +69,10 @@ export function useNotifications(subscriptions: Subscription[]) {
6969
7070 /**
7171 * Marks a notification as read.
72+ * Uses optimistic UI update for instant feedback.
7273 */
73- const markAsRead = useCallback ( async ( id : string ) => {
74- if ( isTauri ( ) ) {
75- await notificationsApi . markAsRead ( id ) ;
76- }
77-
74+ const markAsRead = useCallback ( ( id : string ) => {
75+ // Optimistic update - instant UI feedback
7876 setByTopic ( ( prev ) => {
7977 const topicId = findTopicForNotification ( prev , id ) ;
8078 if ( ! topicId ) return prev ;
@@ -87,31 +85,42 @@ export function useNotifications(subscriptions: Subscription[]) {
8785 ) ;
8886 return new Map ( prev ) . set ( topicId , updated ) ;
8987 } ) ;
88+
89+ // API call in background
90+ if ( isTauri ( ) ) {
91+ notificationsApi . markAsRead ( id ) . catch ( ( err ) => {
92+ console . error ( "Failed to mark as read:" , err ) ;
93+ } ) ;
94+ }
9095 } , [ ] ) ;
9196
9297 /**
9398 * Marks all notifications in a topic as read.
99+ * Uses optimistic UI update for instant feedback.
94100 */
95- const markAllAsRead = useCallback ( async ( subscriptionId : string ) => {
96- if ( isTauri ( ) ) {
97- await notificationsApi . markAllAsRead ( subscriptionId ) ;
98- }
101+ const markAllAsRead = useCallback ( ( subscriptionId : string ) => {
102+ // Optimistic update - instant UI feedback
99103 setByTopic ( ( prev ) => {
100104 const notifs = prev . get ( subscriptionId ) ;
101105 if ( ! notifs ) return prev ;
102106 const updated = notifs . map ( ( n ) => ( { ...n , read : true } ) ) ;
103107 return new Map ( prev ) . set ( subscriptionId , updated ) ;
104108 } ) ;
109+
110+ // API call in background
111+ if ( isTauri ( ) ) {
112+ notificationsApi . markAllAsRead ( subscriptionId ) . catch ( ( err ) => {
113+ console . error ( "Failed to mark all as read:" , err ) ;
114+ } ) ;
115+ }
105116 } , [ ] ) ;
106117
107118 /**
108119 * Deletes a notification.
120+ * Uses optimistic UI update for instant feedback.
109121 */
110- const deleteNotification = useCallback ( async ( id : string ) => {
111- if ( isTauri ( ) ) {
112- await notificationsApi . delete ( id ) ;
113- }
114-
122+ const deleteNotification = useCallback ( ( id : string ) => {
123+ // Optimistic update - instant UI feedback
115124 setByTopic ( ( prev ) => {
116125 const topicId = findTopicForNotification ( prev , id ) ;
117126 if ( ! topicId ) return prev ;
@@ -122,6 +131,13 @@ export function useNotifications(subscriptions: Subscription[]) {
122131 const filtered = notifs . filter ( ( n ) => n . id !== id ) ;
123132 return new Map ( prev ) . set ( topicId , filtered ) ;
124133 } ) ;
134+
135+ // API call in background
136+ if ( isTauri ( ) ) {
137+ notificationsApi . delete ( id ) . catch ( ( err ) => {
138+ console . error ( "Failed to delete notification:" , err ) ;
139+ } ) ;
140+ }
125141 } , [ ] ) ;
126142
127143 /**
0 commit comments