Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save meta on preview #11409

Merged
merged 17 commits into from Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/data/data-core-editor.md
Expand Up @@ -1058,6 +1058,18 @@ Returns true if the post is autosaving, or false otherwise.

Whether the post is autosaving.

### isPreviewingPost

Returns true if the post is being previewed, or false otherwise.

*Parameters*

* state: Global application state.

*Returns*

Whether the post is being previewed.

### getSuggestedPostFormat

Returns a suggested post format for the current post, inferred only if there
Expand Down
9 changes: 6 additions & 3 deletions packages/edit-post/src/store/effects.js
Expand Up @@ -45,24 +45,27 @@ const effects = {

let wasSavingPost = select( 'core/editor' ).isSavingPost();
let wasAutosavingPost = select( 'core/editor' ).isAutosavingPost();
let wasPreviewingPost = select( 'core/editor' ).isPreviewingPost();
// Save metaboxes when performing a full save on the post.
subscribe( () => {
const isSavingPost = select( 'core/editor' ).isSavingPost();
const isAutosavingPost = select( 'core/editor' ).isAutosavingPost();
const isPreviewingPost = select( 'core/editor' ).isPreviewingPost();
const hasActiveMetaBoxes = select( 'core/edit-post' ).hasMetaBoxes();

// Save metaboxes on save completion when past save wasn't an autosave.
// Save metaboxes on save completion, except for autosaves that are not a post preview.
const shouldTriggerMetaboxesSave = (
hasActiveMetaBoxes &&
wasSavingPost &&
! wasAutosavingPost &&
( ! wasAutosavingPost || wasPreviewingPost ) &&
! isSavingPost &&
! isAutosavingPost
( ! isAutosavingPost || isPreviewingPost )
);

// Save current state for next inspection.
wasSavingPost = isSavingPost;
wasAutosavingPost = isAutosavingPost;
wasPreviewingPost = isPreviewingPost;

if ( shouldTriggerMetaboxesSave ) {
store.dispatch( requestMetaBoxUpdates() );
Expand Down
Expand Up @@ -151,7 +151,7 @@ export class PostPreviewButton extends Component {

// Request an autosave. This happens asynchronously and causes the component
// to update when finished.
this.props.autosave();
this.props.autosave( { isPreview: true } );

// Display a 'Generating preview' message in the Preview tab while we wait for the
// autosave to finish.
Expand Down
11 changes: 11 additions & 0 deletions packages/editor/src/store/selectors.js
Expand Up @@ -1487,6 +1487,17 @@ export function isAutosavingPost( state ) {
return isSavingPost( state ) && state.saving.isAutosave;
}

/**
* Returns true if the post is being previewed, or false otherwise.
*
* @param {Object} state Global application state.
*
* @return {boolean} Whether the post is being previewed.
*/
export function isPreviewingPost( state ) {
Copy link
Member

Choose a reason for hiding this comment

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

It's slightly weird that preview would have this side-effect but it wouldn't be evident from selector name. Though I guess it matches the expectation of the action itself.

return isSavingPost( state ) && state.saving.isPreview;
}

/**
* Returns a suggested post format for the current post, inferred only if there
* is a single block within the post and it is of a type known to match a
Expand Down