Skip to content

Commit

Permalink
Edit Site: Fetch template_parts on the client side
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed May 13, 2020
1 parent 1b9fc6f commit d0a8f06
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions packages/edit-site/src/components/template-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ function TemplateLabel( { template, homeId } ) {

export default function TemplateSwitcher( {
ids,
templatePartIds,
activeId,
homeId,
isTemplatePart,
Expand All @@ -69,11 +68,7 @@ export default function TemplateSwitcher( {

const { currentTheme, templates, templateParts } = useSelect(
( select ) => {
const {
getCurrentTheme,
getEntityRecord,
getEntityRecords,
} = select( 'core' );
const { getCurrentTheme, getEntityRecords } = select( 'core' );
return {
currentTheme: getCurrentTheme(),
templates: getEntityRecords( 'postType', 'wp_template' )?.map(
Expand All @@ -88,25 +83,17 @@ export default function TemplateSwitcher( {
slug: template.slug,
} )
),
templateParts: templatePartIds.map( ( id ) => {
const template = getEntityRecord(
'postType',
'wp_template_part',
id
);
return {
label: template ? (
<TemplateLabel template={ template } />
) : (
__( 'Loading…' )
),
value: id,
slug: template ? template.slug : __( 'Loading…' ),
};
} ),
templateParts: getEntityRecords(
'postType',
'wp_template_part'
)?.map( ( templatePart ) => ( {
label: <TemplateLabel template={ templatePart } />,
value: templatePart.id,
slug: templatePart.slug,
} ) ),
};
},
[ templatePartIds, homeId ]
[ homeId ]
);
const [ isAddTemplateOpen, setIsAddTemplateOpen ] = useState( false );
return (
Expand Down

0 comments on commit d0a8f06

Please sign in to comment.