Skip to content
Prev Previous commit
Next Next commit
Make isSavingPost true during entire save, not only when saving the e…
…ntity
  • Loading branch information
jsnajdr committed Jul 10, 2023
commit 92eda2f16ee3f59f8569e5c8c4e6505a97443e6f
22 changes: 5 additions & 17 deletions packages/editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,15 +681,9 @@ export function isDeletingPost( state ) {
*
* @return {boolean} Whether post is being saved.
*/
export const isSavingPost = createRegistrySelector( ( select ) => ( state ) => {
const postType = getCurrentPostType( state );
const postId = getCurrentPostId( state );
return select( coreStore ).isSavingEntityRecord(
'postType',
postType,
postId
);
} );
export function isSavingPost( state ) {
return !! state.saving.pending;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My ultimate goal (probably never happens but who knows) is to make the editor package obsolete (because as an abstraction it's not clear). The change here goes in the opposite direction because it uses the store of this package. I think it's fine for now but I just wanted to share some thought on this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's not just isSavingPost, but also adding a new functionality (the action hook) to the editor.savePost action goes in the opposite direction, too. When the savePost action moves somewhere else (to edit-post?), the isSavingPost selector and the state it reads will move as well.

}

/**
* Returns true if non-post entities are currently being saved, or false otherwise.
Expand Down Expand Up @@ -760,10 +754,7 @@ export const didPostSaveRequestFail = createRegistrySelector(
* @return {boolean} Whether the post is autosaving.
*/
export function isAutosavingPost( state ) {
if ( ! isSavingPost( state ) ) {
return false;
}
return Boolean( state.saving.options?.isAutosave );
return isSavingPost( state ) && Boolean( state.saving.options?.isAutosave );
}

/**
Expand All @@ -774,10 +765,7 @@ export function isAutosavingPost( state ) {
* @return {boolean} Whether the post is being previewed.
*/
export function isPreviewingPost( state ) {
if ( ! isSavingPost( state ) ) {
return false;
}
return Boolean( state.saving.options?.isPreview );
return isSavingPost( state ) && Boolean( state.saving.options?.isPreview );
}

/**
Expand Down