diff --git a/editor/effects.js b/editor/effects.js
index f75379c6c6b25..7e6df9e024ae7 100644
--- a/editor/effects.js
+++ b/editor/effects.js
@@ -27,18 +27,14 @@ export default {
const { dispatch, getState } = store;
const state = getState();
const post = getCurrentPost( state );
- const isNew = ! post.id;
const edits = getPostEdits( state );
const toSend = {
...edits,
content: serialize( getBlocks( state ) ),
+ id: post.id,
};
const transactionId = uniqueId();
- if ( ! isNew ) {
- toSend.id = post.id;
- }
-
dispatch( {
type: 'CLEAR_POST_EDITS',
optimist: { type: BEGIN, id: transactionId },
@@ -58,7 +54,6 @@ export default {
type: 'REQUEST_POST_UPDATE_SUCCESS',
previousPost: post,
post: newPost,
- isNew,
optimist: { type: COMMIT, id: transactionId },
} );
} ).fail( ( err ) => {
@@ -75,7 +70,7 @@ export default {
} );
},
REQUEST_POST_UPDATE_SUCCESS( action, store ) {
- const { previousPost, post, isNew } = action;
+ const { previousPost, post } = action;
const { dispatch } = store;
const publishStatus = [ 'publish', 'private', 'future' ];
@@ -102,13 +97,15 @@ export default {
) );
}
- if ( ! isNew ) {
- return;
+ if ( get( window.history.state, 'id' ) !== post.id ) {
+ window.history.replaceState(
+ { id: post.id },
+ 'Post ' + post.id,
+ getGutenbergURL( {
+ post_id: post.id,
+ } )
+ );
}
- const newURL = getGutenbergURL( {
- post_id: post.id,
- } );
- window.history.replaceState( {}, 'Post ' + post.id, newURL );
},
REQUEST_POST_UPDATE_FAILURE( action, store ) {
const { post, edits } = action;
diff --git a/editor/header/saved-state/index.js b/editor/header/saved-state/index.js
index 8d55efda5bb96..c8b21c1535cc2 100644
--- a/editor/header/saved-state/index.js
+++ b/editor/header/saved-state/index.js
@@ -49,7 +49,10 @@ export function SavedState( { isNew, isDirty, isSaving, isSaveable, status, onSt
}
const onClick = () => {
- onStatusChange( status || 'draft' );
+ if ( 'auto-draft' === status ) {
+ onStatusChange( 'draft' );
+ }
+
onSave();
};
diff --git a/editor/header/saved-state/test/index.js b/editor/header/saved-state/test/index.js
index 9829361f4a0d9..38c33ba633713 100644
--- a/editor/header/saved-state/test/index.js
+++ b/editor/header/saved-state/test/index.js
@@ -46,6 +46,27 @@ describe( 'SavedState', () => {
expect( wrapper.childAt( 1 ).text() ).toBe( 'Saved' );
} );
+ it( 'should edit auto-draft post to draft before save', () => {
+ const statusSpy = jest.fn();
+ const saveSpy = jest.fn();
+ const wrapper = shallow(
+ Of mountains & printing presses
The goal of this new editor is to make adding rich content to WordPress simple and enjoyable. This whole post is composed of pieces of content—somewhat similar to LEGO bricks—that you can move around and interact with. Move your cursor around and you\'ll notice the different blocks light up with outlines and arrows. Press the arrows to reposition blocks quickly, without fearing about losing things in the process of copying and pasting.
', - '', - - '', - 'What you are reading now is a text block, the most basic block of all. The text block has its own controls to be moved freely around the post...
', - '', - - '', - '... like this one, which is right aligned.
', - '', - - '', - - '', - 'Headings are separate blocks as well, which helps with the outline and organization of your content.
', - '', - - '', - 'Handling images and media with the utmost care is a primary focus of the new editor. Hopefully, you\'ll find aspects of adding captions or going full-width with your pictures much easier and robust than before.
', - '', - - '', - '', - '', - - '', - 'Try selecting and removing or editing the caption, now you don\'t have to be careful about selecting the image or other text by mistake and ruining the presentation.
', - '', - - '', - 'Imagine everything that WordPress can do is available to you quickly and in the same place on the interface. No need to figure out HTML tags, classes, or remember complicated shortcode syntax. That\'s the spirit behind the inserter—the (+)
button you\'ll see around the editor—which allows you to browse all available content blocks and insert them into your post. Plugins and themes are able to register their own, opening up all sort of possibilities for rich editing and publishing.
Go give it a try, you may discover things WordPress can already insert into your posts that you didn\'t know about. Here\'s a short list of what you can currently find there:
', - '', - - '', - 'If you want to learn more about how to build additional blocks, or if you are interested in helping with the project, head over to the GitHub repository.
', - '', - - '', - ' ', - '', - - '', - 'A huge benefit of blocks is that you can edit them in place and manipulate your content directly. Instead of having fields for editing things like the source of a quote, or the text of a button, you can directly change the content. Try editing the following quote:
', - '', - - '', - '', - '', - - '', - 'The editor will endeavour to create a new page and post building experience that makes writing rich posts effortless, and has “blocks” to make it easy what today might take shortcodes, custom HTML, or “mystery meat” embed discovery.
The information corresponding to the source of the quote is a separate text field, similar to captions under images, so the structure of the quote is protected even if you select, modify, or remove the source. It\'s always easy to add it back.
', - '', - - '', - 'Blocks can be anything you need. For instance, you may want to insert a subdued quote as part of the composition of your text, or you may prefer to display a giant stylized one. All of these options are available in the inserter.
', - '', - - '', - '', - '', - - '', - 'There is no greater agony than bearing an untold story inside you.
The goal of this new editor is to make adding rich content to WordPress simple and enjoyable. This whole post is composed of pieces of content—somewhat similar to LEGO bricks—that you can move around and interact with. Move your cursor around and you\'ll notice the different blocks light up with outlines and arrows. Press the arrows to reposition blocks quickly, without fearing about losing things in the process of copying and pasting.
', + '', + + '', + 'What you are reading now is a text block, the most basic block of all. The text block has its own controls to be moved freely around the post...
', + '', + + '', + '... like this one, which is right aligned.
', + '', + + '', + + '', + 'Headings are separate blocks as well, which helps with the outline and organization of your content.
', + '', + + '', + 'Handling images and media with the utmost care is a primary focus of the new editor. Hopefully, you\'ll find aspects of adding captions or going full-width with your pictures much easier and robust than before.
', + '', + + '', + '', + '', + + '', + 'Try selecting and removing or editing the caption, now you don\'t have to be careful about selecting the image or other text by mistake and ruining the presentation.
', + '', + + '', + 'Imagine everything that WordPress can do is available to you quickly and in the same place on the interface. No need to figure out HTML tags, classes, or remember complicated shortcode syntax. That\'s the spirit behind the inserter—the (+)
button you\'ll see around the editor—which allows you to browse all available content blocks and insert them into your post. Plugins and themes are able to register their own, opening up all sort of possibilities for rich editing and publishing.
Go give it a try, you may discover things WordPress can already insert into your posts that you didn\'t know about. Here\'s a short list of what you can currently find there:
', + '', + + '', + 'If you want to learn more about how to build additional blocks, or if you are interested in helping with the project, head over to the GitHub repository.
', + '', + + '', + ' ', + '', + + '', + 'Ea veniam homero eam. Ex inimicus molestiae cum, debet scaevola at eos. Vis assum veritus ut, has ea nostrud accusata, offendit appareat comprehensam ea pro. Ad quo quem veritus appellantur, te est quas phaedrum, eum alia habeo ad. Ei est erroribus imperdiet, omnis dicam propriae sed no. His vitae oratio fierent ne, cu duo tota eligendi, electram rationibus in qui.
', - '', + '', + 'A huge benefit of blocks is that you can edit them in place and manipulate your content directly. Instead of having fields for editing things like the source of a quote, or the text of a button, you can directly change the content. Try editing the following quote:
', + '', - '', - '', - '', + '', + '', + '', - '', - 'The editor will endeavour to create a new page and post building experience that makes writing rich posts effortless, and has “blocks” to make it easy what today might take shortcodes, custom HTML, or “mystery meat” embed discovery.
Est quis reque cetero ad. Sea id autem nominavi deseruisse. Veniam qualisque definitionem pri id, ea autem feugiat delenit ius, mei at loem affert accumsan. Dicat eruditi cu est, te pro dicant pericula conclusionemque, ei vim detracto euripidis intellegam. Eius postea volumus mei ad.
', - '', + '', + 'The information corresponding to the source of the quote is a separate text field, similar to captions under images, so the structure of the quote is protected even if you select, modify, or remove the source. It\'s always easy to add it back.
', + '', - '', - 'Prima ridens denique his te, ferri illum volumus an his. Eu vel dicat homero qualisqu, vitae regione deserunt vis ei. Graeci incorrupte liberavisse no mea, saepe voluptaria usu ex, vis dicant euismod id. At dolor reprimique eos, quo altera detraxit moderatius id. Quo iudico utinam eu, ad alia munere mel.
', - '', + '', + 'Blocks can be anything you need. For instance, you may want to insert a subdued quote as part of the composition of your text, or you may prefer to display a giant stylized one. All of these options are available in the inserter.
', + '', - '', - 'export default function MyButton() {\n\
- return <Button>Click Me!</Button>;\n\
+ '',
+ 'There is no greater agony than bearing an untold story inside you.
',
+ '',
+
+ '',
+ '
',
+ '',
+
+ '',
+ 'Sea id autem nominavi deseruisse
',
+ '',
+
+ '',
+ 'Ea veniam homero eam. Ex inimicus molestiae cum, debet scaevola at eos. Vis assum veritus ut, has ea nostrud accusata, offendit appareat comprehensam ea pro. Ad quo quem veritus appellantur, te est quas phaedrum, eum alia habeo ad. Ei est erroribus imperdiet, omnis dicam propriae sed no. His vitae oratio fierent ne, cu duo tota eligendi, electram rationibus in qui.
',
+ '',
+
+ '',
+ '',
+ '',
+
+ '',
+ 'Est quis reque cetero ad. Sea id autem nominavi deseruisse. Veniam qualisque definitionem pri id, ea autem feugiat delenit ius, mei at loem affert accumsan. Dicat eruditi cu est, te pro dicant pericula conclusionemque, ei vim detracto euripidis intellegam. Eius postea volumus mei ad.
',
+ '',
+
+ '',
+ 'Prima ridens denique his te, ferri illum volumus an his. Eu vel dicat homero qualisqu, vitae regione deserunt vis ei. Graeci incorrupte liberavisse no mea, saepe voluptaria usu ex, vis dicant euismod id. At dolor reprimique eos, quo altera detraxit moderatius id. Quo iudico utinam eu, ad alia munere mel.
',
+ '',
+
+ '',
+ 'export default function MyButton() {\n\
+return <Button>Click Me!</Button>;\n\
}
',
- '',
-
- '',
- '',
- '',
- '',
- '',
- '',
-
- '',
- 'An old silent pond...
A frog jumps into the pond,
splash! Silence again.
',
- '',
-
- '',
- 'Eu integre accusata prodesset est, sed te impetus gubergren conceptam, ex sed wisi nostrum ocurreret. Esse velit omittantur ius te, alii dissentias ei vis. At sed unum veritus fabellas. Te volutpat appellantur duo. Ad natum fuisset intellegebat eam, causae invidunt usu id, et vis impetus appetere.
',
- '',
-
- '',
- 'Nominavi deseruisse
',
- '',
-
- '',
- '- Est quis reque cetero ad
- Sea id autem nominavi deseruisse
- Veniam qualisque definitionem pri id, ea autem feugiat delenit ius, mei at loem affert accumsan
- Dicat eruditi cu est, te pro dicant pericula conclusionemque
- Eius postea volumus mei ad
',
- '',
-
- '',
- 'Code is Poetry
',
- '',
-
- '',
- '
',
- '',
-
- // Remove until #1795 is fixed.
- // '',
- // 'Version Musician Date 4.4 Clifford Brown December 8, 2015 4.5 Coleman Hawkins April 12, 2016 4.6 Pepper Adams August 16, 2016 4.7 Sarah Vaughan December 6, 2016
',
- // '',
-
- '',
- 'All that you can embed!
',
- '',
-
- '',
- '',
- '',
-
- '',
- 'https://twitter.com/photomatt/status/868657763970404352',
- '',
-
- '',
- 'https://make.wordpress.org/core/2017/01/17/editor-technical-overview/',
- '',
-
- ].join( '' ),
- },
+ '',
+
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+
+ '',
+ 'An old silent pond...
A frog jumps into the pond,
splash! Silence again.
',
+ '',
+
+ '',
+ 'Eu integre accusata prodesset est, sed te impetus gubergren conceptam, ex sed wisi nostrum ocurreret. Esse velit omittantur ius te, alii dissentias ei vis. At sed unum veritus fabellas. Te volutpat appellantur duo. Ad natum fuisset intellegebat eam, causae invidunt usu id, et vis impetus appetere.
',
+ '',
+
+ '',
+ 'Nominavi deseruisse
',
+ '',
+
+ '',
+ '- Est quis reque cetero ad
- Sea id autem nominavi deseruisse
- Veniam qualisque definitionem pri id, ea autem feugiat delenit ius, mei at loem affert accumsan
- Dicat eruditi cu est, te pro dicant pericula conclusionemque
- Eius postea volumus mei ad
',
+ '',
+
+ '',
+ 'Code is Poetry
',
+ '',
+
+ '',
+ '
',
+ '',
+
+ // Remove until #1795 is fixed.
+ // '',
+ // 'Version Musician Date 4.4 Clifford Brown December 8, 2015 4.5 Coleman Hawkins April 12, 2016 4.6 Pepper Adams August 16, 2016 4.7 Sarah Vaughan December 6, 2016
',
+ // '',
+
+ '',
+ 'All that you can embed!
',
+ '',
+
+ '',
+ '',
+ '',
+
+ '',
+ 'https://twitter.com/photomatt/status/868657763970404352',
+ '',
+
+ '',
+ 'https://make.wordpress.org/core/2017/01/17/editor-technical-overview/',
+ '',
+
+ ].join( '' ),
};