Skip to content

Commit

Permalink
Add isEditedPostSaveable logic to isPostAutosaveable
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Silverstein committed May 24, 2018
1 parent f669754 commit 7b4bb19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 2 additions & 5 deletions editor/components/autosave-monitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import { withSelect, withDispatch } from '@wordpress/data';

export class AutosaveMonitor extends Component {
componentDidUpdate( prevProps ) {
const { isDirty, isSaveable, isAutosaveable, isAutosaving } = this.props;
const { isDirty, isAutosaveable, isAutosaving } = this.props;

// Prevent autosaves if an autosave is in progress.
if ( isAutosaving ) {
return;
}
if (
prevProps.isDirty !== isDirty ||
prevProps.isSaveable !== isSaveable ||
prevProps.isAutosaveable !== isAutosaveable
) {
this.toggleTimer( isDirty && isSaveable && isAutosaveable );
this.toggleTimer( isDirty && isAutosaveable );
}
}

Expand Down Expand Up @@ -45,15 +44,13 @@ export default compose( [
withSelect( ( select ) => {
const {
isEditedPostDirty,
isEditedPostSaveable,
isPostAutosaveable,
getEditorSettings,
isAutosavingPost,
} = select( 'core/editor' );
const { autosaveInterval } = getEditorSettings();
return {
isDirty: isEditedPostDirty(),
isSaveable: isEditedPostSaveable(),
isAutosaveable: isPostAutosaveable(),
autosaveInterval: autosaveInterval,
isAutosaving: isAutosavingPost(),
Expand Down
5 changes: 5 additions & 0 deletions editor/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ export function isPostAutosaveable( state ) {
return false;
}

// A post must contain a title, an excerpt, or non-empty content to be valid for autosaving.
if ( ! isEditedPostSaveable( state ) ) {
return false;
}

// If we don't already have an autosave, the post is autosaveable.
if ( ! hasAutosave( state ) ) {
return true;
Expand Down

0 comments on commit 7b4bb19

Please sign in to comment.