@@ -33,6 +33,8 @@ import {
33
33
moveToTrashAction ,
34
34
restoreAction ,
35
35
deleteAction ,
36
+ markAsReadAction ,
37
+ markAsUnreadAction ,
36
38
} from './dataviews/actions' ;
37
39
import { getPath , updateMenuCounter } from './utils' ;
38
40
@@ -200,6 +202,8 @@ const InboxResponse = ( {
200
202
const [ isMovingToTrash , setIsMovingToTrash ] = useState ( false ) ;
201
203
const [ isRestoring , setIsRestoring ] = useState ( false ) ;
202
204
const [ isDeleting , setIsDeleting ] = useState ( false ) ;
205
+ const [ hasMarkedSelfAsRead , setHasMarkedSelfAsRead ] = useState ( false ) ;
206
+
203
207
const { editEntityRecord } = useDispatch ( 'core' ) ;
204
208
205
209
// When opening a "Mark as spam" link from the email, the InboxResponse component is rendered, so we use a hook here to handle it.
@@ -271,6 +275,15 @@ const InboxResponse = ( {
271
275
onActionComplete ?. ( response . id . toString ( ) ) ;
272
276
} , [ response , registry , onActionComplete ] ) ;
273
277
278
+ const handleMarkAsRead = useCallback ( ( ) => {
279
+ markAsReadAction . callback ( [ response ] , { registry } ) ;
280
+ } , [ response , registry ] ) ;
281
+
282
+ const handleMarkAsUnread = useCallback ( ( ) => {
283
+ setHasMarkedSelfAsRead ( response . id ) ;
284
+ markAsUnreadAction . callback ( [ response ] , { registry } ) ;
285
+ } , [ response , registry ] ) ;
286
+
274
287
const renderActionButtons = ( ) => {
275
288
switch ( response . status ) {
276
289
case 'spam' :
@@ -328,6 +341,28 @@ const InboxResponse = ( {
328
341
default : // 'publish' (inbox) or any other status
329
342
return (
330
343
< >
344
+ { response . is_unread && (
345
+ < Button
346
+ variant = "tertiary"
347
+ onClick = { handleMarkAsRead }
348
+ showTooltip = { true }
349
+ label = { handleMarkAsRead . label }
350
+ iconSize = { 24 }
351
+ icon = { markAsReadAction . icon }
352
+ size = "compact"
353
+ > </ Button >
354
+ ) }
355
+ { ! response . is_unread && (
356
+ < Button
357
+ variant = "tertiary"
358
+ onClick = { handleMarkAsUnread }
359
+ showTooltip = { true }
360
+ label = { markAsUnreadAction . label }
361
+ iconSize = { 24 }
362
+ icon = { markAsUnreadAction . icon }
363
+ size = "compact"
364
+ > </ Button >
365
+ ) }
331
366
< Button
332
367
variant = "tertiary"
333
368
onClick = { handleMarkAsSpam }
@@ -490,9 +525,15 @@ const InboxResponse = ( {
490
525
// Mark feedback as read when viewing
491
526
useEffect ( ( ) => {
492
527
if ( ! response || ! response . id || ! response . is_unread ) {
528
+ setHasMarkedSelfAsRead ( response . id ) ;
529
+ return ;
530
+ }
531
+ if ( hasMarkedSelfAsRead === response . id ) {
493
532
return ;
494
533
}
495
534
535
+ setHasMarkedSelfAsRead ( response . id ) ;
536
+
496
537
// Immediately update entity in store
497
538
editEntityRecord ( 'postType' , 'feedback' , response . id , {
498
539
is_unread : false ,
@@ -512,7 +553,7 @@ const InboxResponse = ( {
512
553
is_unread : true ,
513
554
} ) ;
514
555
} ) ;
515
- } , [ response , editEntityRecord ] ) ;
556
+ } , [ response , editEntityRecord , hasMarkedSelfAsRead ] ) ;
516
557
517
558
const handelImageLoaded = useCallback ( ( ) => {
518
559
return setIsImageLoading ( false ) ;
0 commit comments