Skip to content

Commit

Permalink
Prevent post saving through keyboard if post saving locked (#35361)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidsector9 authored Oct 6, 2021
1 parent 1b53677 commit d4794d6
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,32 @@ import { store as editorStore } from '../../store';

function SaveShortcut( { resetBlocksOnSave } ) {
const { resetEditorBlocks, savePost } = useDispatch( editorStore );
const { isEditedPostDirty, getPostEdits } = useSelect( ( select ) => {
const {
isEditedPostDirty: _isEditedPostDirty,
getPostEdits: _getPostEdits,
} = select( editorStore );

return {
isEditedPostDirty: _isEditedPostDirty,
getPostEdits: _getPostEdits,
};
}, [] );
const { isEditedPostDirty, getPostEdits, isPostSavingLocked } = useSelect(
( select ) => {
const {
isEditedPostDirty: _isEditedPostDirty,
getPostEdits: _getPostEdits,
isPostSavingLocked: _isPostSavingLocked,
} = select( editorStore );

return {
isEditedPostDirty: _isEditedPostDirty,
getPostEdits: _getPostEdits,
isPostSavingLocked: _isPostSavingLocked,
};
},
[]
);
useShortcut( 'core/editor/save', ( event ) => {
event.preventDefault();

/**
* Do not save the post if post saving is locked.
*/
if ( isPostSavingLocked() ) {
return;
}

// TODO: This should be handled in the `savePost` effect in
// considering `isSaveable`. See note on `isEditedPostSaveable`
// selector about dirtiness and meta-boxes.
Expand Down

0 comments on commit d4794d6

Please sign in to comment.