Skip to content

Commit

Permalink
fix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed Oct 25, 2024
1 parent 95d6d1c commit 5b83ef7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.8/template-parts.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function gutenberg_add_default_template_types_to_index( WP_REST_Response $respon
$indexed_template_types[] = $template_type;
}

$response->data['defaultTemplateTypes'] = indexed_template_types();
$response->data['defaultTemplateTypes'] = $indexed_template_types;
return $response;
}

Expand Down
9 changes: 2 additions & 7 deletions packages/block-library/src/template-part/edit/utils/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,9 @@ export function useCreateTemplatePartFromBlocks( area, setAttributes ) {
export function useTemplatePartArea( area ) {
return useSelect(
( select ) => {
// FIXME: @wordpress/block-library should not depend on @wordpress/editor.
// Blocks can be loaded into a *non-post* block editor.
/* eslint-disable @wordpress/data-no-store-string-literals */
const definedAreas =
select(
'core/editor'
).__experimentalGetDefaultTemplatePartAreas();
/* eslint-enable @wordpress/data-no-store-string-literals */
select( coreStore ).getEntityRecord( 'root', '__unstableBase' )
?.defaultTemplatePartAreas || [];

const selectedArea = definedAreas.find(
( definedArea ) => definedArea.area === area
Expand Down
19 changes: 10 additions & 9 deletions packages/editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1716,15 +1716,16 @@ export const __experimentalGetDefaultTemplateTypes = createRegistrySelector(
* @return {Array} The template part areas.
*/
export const __experimentalGetDefaultTemplatePartAreas = createRegistrySelector(
( select ) => () => {
const areas =
select( coreStore ).getEntityRecord( 'root', '__unstableBase' )
?.defaultTemplatePartAreas ?? [];

return areas.map( ( item ) => {
return { ...item, icon: getTemplatePartIcon( item.icon ) };
} );
}
( select ) =>
createSelector( () => {
const areas =
select( coreStore ).getEntityRecord( 'root', '__unstableBase' )
?.defaultTemplatePartAreas || [];

return areas.map( ( item ) => {
return { ...item, icon: getTemplatePartIcon( item.icon ) };
} );
} )
);

/**
Expand Down

0 comments on commit 5b83ef7

Please sign in to comment.