@@ -33,6 +33,8 @@ import {
3333 moveToTrashAction ,
3434 restoreAction ,
3535 deleteAction ,
36+ markAsReadAction ,
37+ markAsUnreadAction ,
3638} from './dataviews/actions' ;
3739import { getPath , updateMenuCounter } from './utils' ;
3840
@@ -200,6 +202,8 @@ const InboxResponse = ( {
200202 const [ isMovingToTrash , setIsMovingToTrash ] = useState ( false ) ;
201203 const [ isRestoring , setIsRestoring ] = useState ( false ) ;
202204 const [ isDeleting , setIsDeleting ] = useState ( false ) ;
205+ const [ hasMarkedSelfAsRead , setHasMarkedSelfAsRead ] = useState ( false ) ;
206+
203207 const { editEntityRecord } = useDispatch ( 'core' ) ;
204208
205209 // 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 = ( {
271275 onActionComplete ?. ( response . id . toString ( ) ) ;
272276 } , [ response , registry , onActionComplete ] ) ;
273277
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+
274287 const renderActionButtons = ( ) => {
275288 switch ( response . status ) {
276289 case 'spam' :
@@ -328,6 +341,28 @@ const InboxResponse = ( {
328341 default : // 'publish' (inbox) or any other status
329342 return (
330343 < >
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+ ) }
331366 < Button
332367 variant = "tertiary"
333368 onClick = { handleMarkAsSpam }
@@ -490,9 +525,15 @@ const InboxResponse = ( {
490525 // Mark feedback as read when viewing
491526 useEffect ( ( ) => {
492527 if ( ! response || ! response . id || ! response . is_unread ) {
528+ setHasMarkedSelfAsRead ( response . id ) ;
529+ return ;
530+ }
531+ if ( hasMarkedSelfAsRead === response . id ) {
493532 return ;
494533 }
495534
535+ setHasMarkedSelfAsRead ( response . id ) ;
536+
496537 // Immediately update entity in store
497538 editEntityRecord ( 'postType' , 'feedback' , response . id , {
498539 is_unread : false ,
@@ -512,7 +553,7 @@ const InboxResponse = ( {
512553 is_unread : true ,
513554 } ) ;
514555 } ) ;
515- } , [ response , editEntityRecord ] ) ;
556+ } , [ response , editEntityRecord , hasMarkedSelfAsRead ] ) ;
516557
517558 const handelImageLoaded = useCallback ( ( ) => {
518559 return setIsImageLoading ( false ) ;
0 commit comments