Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Forms: toggling read/unread currently leaves dirty records, fix depends on core store unstable mechanics
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const ResponseViewBody = ( {
const [ isImageLoading, setIsImageLoading ] = useState( true );
const [ hasMarkedSelfAsRead, setHasMarkedSelfAsRead ] = useState( 0 );

const { editEntityRecord } = useDispatch( 'core' );
const { editEntityRecord, saveEditedEntityRecord } = useDispatch( 'core' );

const emptyTrashDays = useConfigValue( 'emptyTrashDays' ) ?? 0;

Expand Down Expand Up @@ -376,10 +376,13 @@ const ResponseViewBody = ( {
}

// Then update on server
apiFetch( {
path: `/wp/v2/feedback/${ response.id }/read`,
method: 'POST',
data: { is_unread: false },
saveEditedEntityRecord( 'postType', 'feedback', response.id, {
__unstableFetch: () =>
apiFetch( {
path: `/wp/v2/feedback/${ response.id }/read`,
method: 'POST',
data: { is_unread: false },
} ),
} )
.then( ( { count }: { count: number } ) => {
// Update menu counter with accurate count from server
Expand Down Expand Up @@ -407,6 +410,7 @@ const ResponseViewBody = ( {
invalidateCounts,
markRecordsAsInvalid,
currentQuery,
saveEditedEntityRecord,
] );

const handelImageLoaded = useCallback( () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ export const markAsReadAction: Action = {
multiple: items.length > 1,
} );

const { editEntityRecord } = registry.dispatch( coreStore );
const { editEntityRecord, saveEditedEntityRecord } = registry.dispatch( coreStore );
const { getEntityRecord } = registry.select( coreStore );
const { createSuccessNotice, createErrorNotice } = registry.dispatch( noticesStore );
const { invalidateCounts, markRecordsAsInvalid } = registry.dispatch( dashboardStore );
Expand All @@ -592,12 +592,15 @@ export const markAsReadAction: Action = {
}

// Update on server
return apiFetch( {
path: `/wp/v2/feedback/${ id }/read`,
method: 'POST',
data: { is_unread: false },
return saveEditedEntityRecord( 'postType', 'feedback', id, {
__unstableFetch: () =>
apiFetch( {
path: `/wp/v2/feedback/${ id }/read`,
method: 'POST',
data: { is_unread: false },
} ),
} )
.then( ( { count } ) => {
.then( ( { count }: { count: number } ) => {
// Update menu counter with accurate count from server.
updateMenuCounter( count );
} )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export type Registry = {
name: string,
record: Record< string, unknown >
) => Promise< void >;
saveEditedEntityRecord: (
kind: string,
name: string,
recordId: number,
options?: { __unstableFetch?: () => Promise< void > }
) => Promise< { id: string; count: number } >;
deleteEntityRecord: (
kind: string,
name: string,
Expand Down
Loading