Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit Post: Use hooks instead of HoCs in 'PostStatus' components #54951

Merged
merged 2 commits into from Oct 2, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 19 additions & 25 deletions packages/edit-post/src/components/sidebar/post-status/index.js
Expand Up @@ -6,8 +6,7 @@ import {
__experimentalHStack as HStack,
PanelBody,
} from '@wordpress/components';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose, ifCondition } from '@wordpress/compose';
import { useDispatch, useSelect } from '@wordpress/data';
import { PostSwitchToDraftButton, PostSyncStatus } from '@wordpress/editor';

/**
Expand All @@ -31,13 +30,29 @@ import PostURL from '../post-url';
*/
const PANEL_NAME = 'post-status';

function PostStatus( { isOpened, onTogglePanel } ) {
export default function PostStatus() {
const { isOpened, isRemoved } = useSelect( ( select ) => {
// We use isEditorPanelRemoved to hide the panel if it was programatically removed. We do
// not use isEditorPanelEnabled since this panel should not be disabled through the UI.
const { isEditorPanelRemoved, isEditorPanelOpened } =
select( editPostStore );
return {
isRemoved: isEditorPanelRemoved( PANEL_NAME ),
isOpened: isEditorPanelOpened( PANEL_NAME ),
};
}, [] );
const { toggleEditorPanelOpened } = useDispatch( editPostStore );

if ( isRemoved ) {
return null;
}

return (
<PanelBody
className="edit-post-post-status"
title={ __( 'Summary' ) }
opened={ isOpened }
onToggle={ onTogglePanel }
onToggle={ () => toggleEditorPanelOpened( PANEL_NAME ) }
>
<PluginPostStatusInfo.Slot>
{ ( fills ) => (
Expand Down Expand Up @@ -69,24 +84,3 @@ function PostStatus( { isOpened, onTogglePanel } ) {
</PanelBody>
);
}

export default compose( [
withSelect( ( select ) => {
// We use isEditorPanelRemoved to hide the panel if it was programatically removed. We do
// not use isEditorPanelEnabled since this panel should not be disabled through the UI.
const { isEditorPanelRemoved, isEditorPanelOpened } =
select( editPostStore );
return {
isRemoved: isEditorPanelRemoved( PANEL_NAME ),
isOpened: isEditorPanelOpened( PANEL_NAME ),
};
} ),
ifCondition( ( { isRemoved } ) => ! isRemoved ),
withDispatch( ( dispatch ) => ( {
onTogglePanel() {
return dispatch( editPostStore ).toggleEditorPanelOpened(
PANEL_NAME
);
},
} ) ),
] )( PostStatus );

This file was deleted.

1 change: 0 additions & 1 deletion packages/edit-post/src/style.scss
Expand Up @@ -14,7 +14,6 @@
@import "./components/sidebar/post-format/style.scss";
@import "./components/sidebar/post-schedule/style.scss";
@import "./components/sidebar/post-slug/style.scss";
@import "./components/sidebar/post-status/style.scss";
@import "./components/sidebar/post-template/style.scss";
@import "./components/sidebar/post-url/style.scss";
@import "./components/sidebar/post-visibility/style.scss";
Expand Down