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
6 changes: 4 additions & 2 deletions packages/editor/src/components/post-saved-state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class PostSavedState extends Component {
}

render() {
const { isNew, isPublished, isDirty, isSaving, isSaveable, onSave, isAutosaving } = this.props;
const { isNew, isScheduled, isPublished, isDirty, isSaving, isSaveable, onSave, isAutosaving } = this.props;
const { forceSavedMessage } = this.state;
if ( isSaving ) {
// TODO: Classes generation should be common across all return
Expand All @@ -59,7 +59,7 @@ export class PostSavedState extends Component {
);
}

if ( isPublished ) {
if ( isPublished || isScheduled ) {
return <PostSwitchToDraftButton />;
}

Expand Down Expand Up @@ -94,6 +94,7 @@ export default compose( [
const {
isEditedPostNew,
isCurrentPostPublished,
isCurrentPostScheduled,
isEditedPostDirty,
isSavingPost,
isEditedPostSaveable,
Expand All @@ -104,6 +105,7 @@ export default compose( [
post: getCurrentPost(),
isNew: isEditedPostNew(),
isPublished: isCurrentPostPublished(),
isScheduled: isCurrentPostScheduled(),
isDirty: forceIsDirty || isEditedPostDirty(),
isSaving: forceIsSaving || isSavingPost(),
isSaveable: isEditedPostSaveable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ import { __ } from '@wordpress/i18n';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';

function PostSwitchToDraftButton( { isSaving, isPublished, onClick } ) {
if ( ! isPublished ) {
function PostSwitchToDraftButton( { isSaving, isPublished, isScheduled, onClick } ) {
if ( ! isPublished && ! isScheduled ) {
return null;
}

const onSwitch = () => {
let alertMessage;
if ( isPublished ) {
alertMessage = __( 'Are you sure you want to unpublish this post?' );
} else if ( isScheduled ) {
alertMessage = __( 'Are you sure you want to unschedule this post?' );
}
// eslint-disable-next-line no-alert
if ( window.confirm( __( 'Are you sure you want to unpublish this post?' ) ) ) {
if ( window.confirm( alertMessage ) ) {
onClick();
}
};
Expand All @@ -32,10 +38,11 @@ function PostSwitchToDraftButton( { isSaving, isPublished, onClick } ) {

export default compose( [
withSelect( ( select ) => {
const { isSavingPost, isCurrentPostPublished } = select( 'core/editor' );
const { isSavingPost, isCurrentPostPublished, isCurrentPostScheduled } = select( 'core/editor' );
return {
isSaving: isSavingPost(),
isPublished: isCurrentPostPublished(),
isScheduled: isCurrentPostScheduled(),
};
} ),
withDispatch( ( dispatch ) => {
Expand Down