@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
83 lines (68 loc) • 1.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _element = require("@wordpress/element");
var _components = require("@wordpress/components");
var _i18n = require("@wordpress/i18n");
var _data = require("@wordpress/data");
var _compose = require("@wordpress/compose");
/**
* WordPress dependencies
*/
function PostSwitchToDraftButton({
isSaving,
isPublished,
isScheduled,
onClick
}) {
const isMobileViewport = (0, _compose.useViewportMatch)('small', '<');
if (!isPublished && !isScheduled) {
return null;
}
const onSwitch = () => {
let alertMessage;
if (isPublished) {
alertMessage = (0, _i18n.__)('Are you sure you want to unpublish this post?');
} else if (isScheduled) {
alertMessage = (0, _i18n.__)('Are you sure you want to unschedule this post?');
} // eslint-disable-next-line no-alert
if (window.confirm(alertMessage)) {
onClick();
}
};
return (0, _element.createElement)(_components.Button, {
className: "editor-post-switch-to-draft",
onClick: onSwitch,
disabled: isSaving,
isTertiary: true
}, isMobileViewport ? (0, _i18n.__)('Draft') : (0, _i18n.__)('Switch to draft'));
}
var _default = (0, _compose.compose)([(0, _data.withSelect)(select => {
const {
isSavingPost,
isCurrentPostPublished,
isCurrentPostScheduled
} = select('core/editor');
return {
isSaving: isSavingPost(),
isPublished: isCurrentPostPublished(),
isScheduled: isCurrentPostScheduled()
};
}), (0, _data.withDispatch)(dispatch => {
const {
editPost,
savePost
} = dispatch('core/editor');
return {
onClick: () => {
editPost({
status: 'draft'
});
savePost();
}
};
})])(PostSwitchToDraftButton);
exports.default = _default;
//# sourceMappingURL=index.js.map