Skip to content

Commit

Permalink
Show all template parts
Browse files Browse the repository at this point in the history
  • Loading branch information
david-szabo97 committed Sep 30, 2020
1 parent 4036921 commit 5b76047
Showing 1 changed file with 5 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,16 @@ import {
import TemplatePreview from '../template-preview';
import NavigationItemWithIcon from '../navigation-item-with-icon';

export default function TemplatePartsMenu( {
activeId,
onActiveTemplatePartIdChange,
} ) {
export default function TemplatePartsMenu( { onActiveTemplatePartIdChange } ) {
const [ hoveredTemplatePartId, setHoveredTemplatePartId ] = useState();

const onMouseEnterTemplatePart = ( id ) => setHoveredTemplatePartId( id );
const onMouseLeaveTemplatePart = () => setHoveredTemplatePartId( null );

const templateParts = useSelect(
( select ) => {
const { getEntityRecord, getEntityRecords } = select( 'core' );

const currentTemplate = getEntityRecord(
'postType',
'wp_template',
activeId
);

return currentTemplate
? getEntityRecords( 'postType', 'wp_template_part', {
resolved: true,
template: currentTemplate.slug,
} )
: null;
},
[ activeId ]
( select ) =>
select( 'core' ).getEntityRecords( 'postType', 'wp_template_part' ),
[]
);

return (
Expand Down Expand Up @@ -70,9 +53,7 @@ export default function TemplatePartsMenu( {
);
} ) }

{ ( ! templateParts || templateParts.length === 0 ) && (
<NavigationItem title={ __( 'Loading…' ) } />
) }
{ ! templateParts && <NavigationItem title={ __( 'Loading…' ) } /> }

{ hoveredTemplatePartId && (
<TemplatePreview entityId={ hoveredTemplatePartId } />
Expand Down

0 comments on commit 5b76047

Please sign in to comment.