Skip to content

Commit

Permalink
Filter edits & enable throwing Error in __unstablePreSavePost filter
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsilverstein committed May 8, 2024
1 parent 101c0d1 commit bcae174
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,8 @@ export const savePost =
dispatch.editPost( { content }, { undoIgnore: true } );
}

if (
! ( await applyFilters(
'editor.__unstablePreSavePost',
Promise.resolve( true ),
options
) )
) {
return;
}

const previousRecord = select.getCurrentPost();
const edits = {
let edits = {
id: previousRecord.id,
...registry
.select( coreStore )
Expand All @@ -205,23 +195,38 @@ export const savePost =
),
content,
};
dispatch( { type: 'REQUEST_POST_UPDATE_START', options } );
await registry
.dispatch( coreStore )
.saveEntityRecord(
'postType',
previousRecord.type,
let error;
try {
edits = await applyFilters(
'editor.__unstablePreSavePost',
edits,
options
);
} catch ( err ) {
error = err;
}

let error = registry
.select( coreStore )
.getLastEntitySaveError(
'postType',
previousRecord.type,
previousRecord.id
);
dispatch( { type: 'REQUEST_POST_UPDATE_START', options } );
if ( ! error ) {
error = await registry
.dispatch( coreStore )
.saveEntityRecord(
'postType',
previousRecord.type,
edits,
options
);
}

if ( ! error ) {
error = registry
.select( coreStore )
.getLastEntitySaveError(
'postType',
previousRecord.type,
previousRecord.id
);
}

if ( ! error ) {
await applyFilters(
Expand Down

0 comments on commit bcae174

Please sign in to comment.