@@ -312,13 +312,16 @@ export const markAsReadAction = {
312312 async callback ( items , { registry } ) {
313313 const { editEntityRecord } = registry . dispatch ( coreStore ) ;
314314 const { createSuccessNotice, createErrorNotice } = registry . dispatch ( noticesStore ) ;
315+
315316 const promises = await Promise . allSettled (
316- items . map ( async ( { id } ) => {
317+ items . map ( async ( { id, status } ) => {
317318 // Update entity in store
318319 editEntityRecord ( 'postType' , 'feedback' , id , { is_unread : false } ) ;
319320
320- // Immediately update menu counters optimistically to avoid delays
321- updateMenuCounterOptimistically ( - items . length ) ;
321+ // Immediately update menu counters optimistically to avoid delays, but only for inbox
322+ if ( status === 'publish' ) {
323+ updateMenuCounterOptimistically ( - 1 ) ;
324+ }
322325
323326 // Update on server
324327 return apiFetch ( {
@@ -327,15 +330,17 @@ export const markAsReadAction = {
327330 data : { is_unread : false } ,
328331 } )
329332 . then ( ( { count } ) => {
330- // Update the unread count in the menu .
333+ // Update menu counter with accurate count from server .
331334 updateMenuCounter ( count ) ;
332335 } )
333336 . catch ( ( ) => {
334337 // Revert the change in the store if the server update fails.
335338 editEntityRecord ( 'postType' , 'feedback' , id , { is_unread : true } ) ;
336339
337- // Revert the change in the sidebar
338- updateMenuCounterOptimistically ( items . length ) ;
340+ // Revert the optimistic change in the sidebar.
341+ if ( status === 'publish' ) {
342+ updateMenuCounterOptimistically ( 1 ) ;
343+ }
339344
340345 throw new Error ( 'Failed to mark as read' ) ;
341346 } ) ;
@@ -386,12 +391,14 @@ export const markAsUnreadAction = {
386391 const { editEntityRecord } = registry . dispatch ( coreStore ) ;
387392 const { createSuccessNotice, createErrorNotice } = registry . dispatch ( noticesStore ) ;
388393 const promises = await Promise . allSettled (
389- items . map ( async ( { id } ) => {
394+ items . map ( async ( { id, status } ) => {
390395 // Update entity in store
391396 editEntityRecord ( 'postType' , 'feedback' , id , { is_unread : true } ) ;
392397
393- // Immediately update menu counters optimistically to avoid delays
394- updateMenuCounterOptimistically ( items . length ) ;
398+ // Immediately update menu counters optimistically to avoid delays, but only for inbox
399+ if ( status === 'publish' ) {
400+ updateMenuCounterOptimistically ( 1 ) ;
401+ }
395402
396403 // Update on server
397404 return apiFetch ( {
@@ -400,15 +407,17 @@ export const markAsUnreadAction = {
400407 data : { is_unread : true } ,
401408 } )
402409 . then ( ( { count } ) => {
403- // Update the unread count in the menu .
410+ // Update menu counter with accurate count from server .
404411 updateMenuCounter ( count ) ;
405412 } )
406413 . catch ( ( ) => {
407414 // Revert the change in the store if the server update fails.
408415 editEntityRecord ( 'postType' , 'feedback' , id , { is_unread : false } ) ;
409416
410- // Revert the change in the sidebar
411- updateMenuCounterOptimistically ( - items . length ) ;
417+ // Revert the optimistic change in the sidebar.
418+ if ( status === 'publish' ) {
419+ updateMenuCounterOptimistically ( - 1 ) ;
420+ }
412421
413422 throw new Error ( 'Failed to mark as unread' ) ;
414423 } ) ;
0 commit comments