Skip to content

Commit

Permalink
Remove use of saveEditedEntityRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
mikachan committed Dec 11, 2024
1 parent bc1b218 commit 2cfd817
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
19 changes: 4 additions & 15 deletions packages/editor/src/components/post-actions/set-as-homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,14 @@ const SetAsHomepageModal = ( { items, closeModal } ) => {
}
);

const { saveEditedEntityRecord, saveEntityRecord } =
useDispatch( coreStore );
const { saveEntityRecord } = useDispatch( coreStore );
const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore );

async function onSetPageAsHomepage( event ) {
event.preventDefault();

try {
// Save new home page settings.
await saveEditedEntityRecord( 'root', 'site', undefined, {
page_on_front: item.id,
show_on_front: 'page',
} );

// This second call to a save function is a workaround for a bug in
// `saveEditedEntityRecord`. This forces the root site settings to be updated.
// See https://github.com/WordPress/gutenberg/issues/67161.
await saveEntityRecord( 'root', 'site', {
page_on_front: item.id,
show_on_front: 'page',
Expand All @@ -66,11 +56,10 @@ const SetAsHomepageModal = ( { items, closeModal } ) => {
type: 'snackbar',
} );
} catch ( error ) {
const typedError = error;
const errorMessage =
typedError.message && typedError.code !== 'unknown_error'
? typedError.message
: __( 'An error occurred while setting the homepage' );
error.message && error.code !== 'unknown_error'
? error.message
: __( 'An error occurred while setting the homepage.' );
createErrorNotice( errorMessage, { type: 'snackbar' } );
} finally {
closeModal?.();
Expand Down
19 changes: 4 additions & 15 deletions packages/editor/src/components/post-actions/set-as-posts-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,14 @@ const SetAsPostsPageModal = ( { items, closeModal } ) => {
}
);

const { saveEditedEntityRecord, saveEntityRecord } =
useDispatch( coreStore );
const { saveEntityRecord } = useDispatch( coreStore );
const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore );

async function onSetPageAsPostsPage( event ) {
event.preventDefault();

try {
// Save new posts page settings.
await saveEditedEntityRecord( 'root', 'site', undefined, {
page_for_posts: item.id,
show_on_front: 'page',
} );

// This second call to a save function is a workaround for a bug in
// `saveEditedEntityRecord`. This forces the root site settings to be updated.
// See https://github.com/WordPress/gutenberg/issues/67161.
await saveEntityRecord( 'root', 'site', {
page_for_posts: item.id,
show_on_front: 'page',
Expand All @@ -66,11 +56,10 @@ const SetAsPostsPageModal = ( { items, closeModal } ) => {
type: 'snackbar',
} );
} catch ( error ) {
const typedError = error;
const errorMessage =
typedError.message && typedError.code !== 'unknown_error'
? typedError.message
: __( 'An error occurred while setting the posts page' );
error.message && error.code !== 'unknown_error'
? error.message
: __( 'An error occurred while setting the posts page.' );
createErrorNotice( errorMessage, { type: 'snackbar' } );
} finally {
closeModal?.();
Expand Down

0 comments on commit 2cfd817

Please sign in to comment.