Skip to content

Commit

Permalink
Chrome: Show notices on post save, schedule, update
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jun 28, 2017
1 parent ecea4ef commit 0ac334f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
3 changes: 2 additions & 1 deletion components/notice/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
position: fixed;
top: 40px;
right: 0;
width: 300px;
min-width: 300px;
max-width: 400px;
z-index: z-index( ".components-notice-list" );
}
54 changes: 47 additions & 7 deletions editor/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { __ } from 'i18n';
* Internal dependencies
*/
import { getGutenbergURL, getWPAdminURL } from './utils/url';
import { focusBlock, replaceBlocks } from './actions';
import { focusBlock, replaceBlocks, successNotice, errorNotice } from './actions';
import {
getCurrentPostId,
getCurrentPost,
getCurrentPostType,
getBlocks,
getPostEdits,
Expand All @@ -26,8 +26,8 @@ export default {
REQUEST_POST_UPDATE( action, store ) {
const { dispatch, getState } = store;
const state = getState();
const postId = getCurrentPostId( state );
const isNew = ! postId;
const post = getCurrentPost( state );
const isNew = ! post.id;
const edits = getPostEdits( state );
const toSend = {
...edits,
Expand All @@ -36,7 +36,7 @@ export default {
const transactionId = uniqueId();

if ( ! isNew ) {
toSend.id = postId;
toSend.id = post.id;
}

dispatch( {
Expand All @@ -56,6 +56,7 @@ export default {
} );
dispatch( {
type: 'REQUEST_POST_UPDATE_SUCCESS',
previousPost: post,
post: newPost,
isNew,
optimist: { type: COMMIT, id: transactionId },
Expand All @@ -67,13 +68,36 @@ export default {
code: 'unknown_error',
message: __( 'An unknown error occurred.' ),
} ),
post,
edits,
optimist: { type: REVERT, id: transactionId },
} );
} );
},
REQUEST_POST_UPDATE_SUCCESS( action ) {
const { post, isNew } = action;
REQUEST_POST_UPDATE_SUCCESS( action, store ) {
const { previousPost, post, isNew } = action;
const { dispatch } = store;

const publishStatus = [ 'publish', 'private', 'future' ];
const isPublished = publishStatus.indexOf( previousPost.status ) !== -1;
const messages = {
publish: __( 'Post published!' ),
'private': __( 'Post published privately!' ),
future: __( 'Post schduled!' ),
};
if ( isPublished || publishStatus.indexOf( post.status ) !== -1 ) {
const noticeMessage = ! isPublished && publishStatus.indexOf( post.status ) !== -1
? messages[ post.status ]
: __( 'Post updated!' );
dispatch( successNotice(
<p>
<span>{ noticeMessage }</span>
{ ' ' }
<a href={ post.link } target="_blank">{ __( 'View post' ) }</a>
</p>
) );
}

if ( ! isNew ) {
return;
}
Expand All @@ -82,6 +106,22 @@ export default {
} );
window.history.replaceState( {}, 'Post ' + post.id, newURL );
},
REQUEST_POST_UPDATE_FAILURE( action, store ) {
const { post, edits } = action;
const { dispatch } = store;

const publishStatus = [ 'publish', 'private', 'future' ];
const isPublished = publishStatus.indexOf( post.status ) !== -1;
const messages = {
publish: __( 'Publishing failed' ),
'private': __( 'Publishing failed' ),
future: __( 'Scheduling failed' ),
};
const noticeMessage = ! isPublished && publishStatus.indexOf( edits.status ) !== -1
? messages[ edits.status ]
: __( 'Updating failed' );
dispatch( errorNotice( noticeMessage ) );
},
TRASH_POST( action, store ) {
const { dispatch, getState } = store;
const { postId } = action;
Expand Down

0 comments on commit 0ac334f

Please sign in to comment.