Skip to content

Commit

Permalink
Chrome: Adding the trash post link to the sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed May 23, 2017
1 parent 3b2d42f commit 0a13bea
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
7 changes: 7 additions & 0 deletions editor/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ export function savePost( dispatch, postId, edits ) {
} );
}

export function trashPost( dispatch, postId ) {
new wp.api.models.Post( { id: postId } ).destroy().done( () => {
const [ baseUrl ] = window.location.href.split( '?' );
window.location = baseUrl + '?page=gutenberg';
} );
}

export function mergeBlocks( dispatch, blockA, blockB ) {
const blockASettings = wp.blocks.getBlockSettings( blockA.blockType );

Expand Down
4 changes: 4 additions & 0 deletions editor/sidebar/post-status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import FormToggle from 'components/form-toggle';
*/
import './style.scss';
import PostVisibility from '../post-visibility';
import PostTrash from '../post-trash';
import { getEditedPostStatus, getSuggestedPostFormat } from '../../selectors';
import { editPost } from '../../actions';

Expand Down Expand Up @@ -46,6 +47,9 @@ function PostStatus( { status, onUpdateStatus, suggestedFormat } ) {
<span>{ __( 'Post Format' ) }</span>
<span>{ format }</span>
</div>
<div className="editor-post-status__row">
<PostTrash />
</div>
</PanelBody>
);
/* eslint-enable jsx-a11y/label-has-for */
Expand Down
48 changes: 48 additions & 0 deletions editor/sidebar/post-trash/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* External dependencies
*/
import { connect } from 'react-redux';

/**
* WordPress dependencies
*/
import { __ } from 'i18n';
import Button from 'components/button';
import Dashicon from 'components/dashicon';

/**
* Internal dependencies
*/
import './style.scss';
import { getCurrentPost } from '../../selectors';
import { trashPost } from '../../actions';

function PostTrash( { postId, ...props } ) {
if ( ! postId ) {
return null;
}

const onClick = () => props.trashPost( postId );

return (
<Button className="editor-post-trash" onClick={ onClick }>
{ __( 'Move to trash' ) }
<Dashicon icon="trash" />
</Button>
);
}

export default connect(
( state ) => {
return {
postId: getCurrentPost( state ).id,
};
},
( dispatch ) => {
return {
trashPost( postId ) {
return trashPost( dispatch, postId );
},
};
}
)( PostTrash );
16 changes: 16 additions & 0 deletions editor/sidebar/post-trash/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.editor-post-trash {
cursor: pointer;
color: inherit;
flex-grow: 1;
text-align: right;

.dashicon {
vertical-align: middle;
margin-right: -10px;
margin-left: 10px;
}

&:hover {
color: $blue-medium;
}
}

0 comments on commit 0a13bea

Please sign in to comment.