Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, postType ) {
new wp.api.models.Post( { id: postId } ).destroy().done( () => {
window.location.href = 'edit.php?post_type=' + postType
+ '&trashed=1&ids=' + postId;
} );
}

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
50 changes: 50 additions & 0 deletions editor/sidebar/post-trash/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* 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, postType, ...props } ) {
if ( ! postId ) {
return null;
}

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

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

export default connect(
( state ) => {
const post = getCurrentPost( state );
return {
postId: post.id,
postType: post.type,
};
},
( dispatch ) => {
return {
trashPost( postId, postType ) {
return trashPost( dispatch, postId, postType );
},
};
}
)( 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;
}
}