Skip to content

Commit

Permalink
Editor: use hooks instead of HoCs in PostExcerpt (#55189)
Browse files Browse the repository at this point in the history
* Editor: use hooks instead of HoCs in PostExcerpt

* remove unneeded isRemoved handling
  • Loading branch information
retrofox authored Oct 10, 2023
1 parent 7aa5a91 commit 9d15719
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions packages/edit-post/src/components/sidebar/post-excerpt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
PostExcerpt as PostExcerptForm,
PostExcerptCheck,
} from '@wordpress/editor';
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -20,7 +19,20 @@ import { store as editPostStore } from '../../../store';
*/
const PANEL_NAME = 'post-excerpt';

function PostExcerpt( { isEnabled, isOpened, onTogglePanel } ) {
export default function PostExcerpt() {
const { isOpened, isEnabled } = useSelect( ( select ) => {
const { isEditorPanelOpened, isEditorPanelEnabled } =
select( editPostStore );

return {
isOpened: isEditorPanelOpened( PANEL_NAME ),
isEnabled: isEditorPanelEnabled( PANEL_NAME ),
};
}, [] );

const { toggleEditorPanelOpened } = useDispatch( editPostStore );
const toggleExcerptPanel = () => toggleEditorPanelOpened( PANEL_NAME );

if ( ! isEnabled ) {
return null;
}
Expand All @@ -30,27 +42,10 @@ function PostExcerpt( { isEnabled, isOpened, onTogglePanel } ) {
<PanelBody
title={ __( 'Excerpt' ) }
opened={ isOpened }
onToggle={ onTogglePanel }
onToggle={ toggleExcerptPanel }
>
<PostExcerptForm />
</PanelBody>
</PostExcerptCheck>
);
}

export default compose( [
withSelect( ( select ) => {
return {
isEnabled:
select( editPostStore ).isEditorPanelEnabled( PANEL_NAME ),
isOpened: select( editPostStore ).isEditorPanelOpened( PANEL_NAME ),
};
} ),
withDispatch( ( dispatch ) => ( {
onTogglePanel() {
return dispatch( editPostStore ).toggleEditorPanelOpened(
PANEL_NAME
);
},
} ) ),
] )( PostExcerpt );

0 comments on commit 9d15719

Please sign in to comment.