Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Site Editor: Use server definition for the Template Areas
  • Loading branch information
Mamaduka committed Dec 8, 2021
commit 6a21fb6f8f3cb6cf98f96f56ddeecebd2bb7d3b3
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,44 @@ import {
Button,
__experimentalHeading as Heading,
} from '@wordpress/components';
import { getTemplatePartIcon } from '@wordpress/editor';
import { store as editorStore } from '@wordpress/editor';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { store as editSiteStore } from '../../../store';
import { TEMPLATE_PART_AREA_TO_NAME } from '../../../store/constants';

function TemplateAreaItem( { area, clientId } ) {
const { selectBlock, toggleBlockHighlight } = useDispatch(
blockEditorStore
);
const { icon, label } = useSelect(
( select ) => {
const defaultAreas = select(
editorStore
).__experimentalGetDefaultTemplatePartAreas();

const matchedArea = defaultAreas.find(
( defaultArea ) => defaultArea.area === area
);

return {
icon: matchedArea?.icon,
label: matchedArea?.label,
};
},
[ area ]
);

const highlightBlock = () => toggleBlockHighlight( clientId, true );
const cancelHighlightBlock = () => toggleBlockHighlight( clientId, false );

return (
<Button
className="edit-site-template-card__template-areas-item"
icon={ getTemplatePartIcon( area ) }
icon={ icon }
onMouseOver={ highlightBlock }
onMouseLeave={ cancelHighlightBlock }
onFocus={ highlightBlock }
Expand All @@ -35,7 +52,7 @@ function TemplateAreaItem( { area, clientId } ) {
selectBlock( clientId );
} }
>
{ TEMPLATE_PART_AREA_TO_NAME[ area ] }
{ label }
</Button>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import { sprintf, __ } from '@wordpress/i18n';
import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { getTemplatePartIcon } from '@wordpress/editor';
import { store as editorStore } from '@wordpress/editor';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { moreVertical } from '@wordpress/icons';

/**
* Internal dependencies
*/
import { store as editSiteStore } from '../../store';
import { TEMPLATE_PART_AREA_TO_NAME } from '../../store/constants';
import isTemplateRevertable from '../../utils/is-template-revertable';

function TemplatePartItemMore( {
Expand Down Expand Up @@ -67,6 +66,23 @@ function TemplatePartItem( {
const { selectBlock, toggleBlockHighlight } = useDispatch(
blockEditorStore
);
const { icon, label } = useSelect(
( select ) => {
const defaultAreas = select(
editorStore
).__experimentalGetDefaultTemplatePartAreas();

const matchedArea = defaultAreas.find(
( defaultArea ) => defaultArea.area === templatePart.area
);

return {
icon: matchedArea?.icon,
label: matchedArea?.label,
};
},
[ templatePart.area ]
);
const highlightBlock = () => toggleBlockHighlight( clientId, true );
const cancelHighlightBlock = () => toggleBlockHighlight( clientId, false );

Expand All @@ -77,7 +93,7 @@ function TemplatePartItem( {
>
<MenuItem
role="button"
icon={ getTemplatePartIcon( templatePart.area ) }
icon={ icon }
iconPosition="left"
onClick={ () => {
selectBlock( clientId );
Expand All @@ -87,7 +103,7 @@ function TemplatePartItem( {
onFocus={ highlightBlock }
onBlur={ cancelHighlightBlock }
>
{ TEMPLATE_PART_AREA_TO_NAME[ templatePart.area ] }
{ label }
</MenuItem>

<DropdownMenu
Expand Down
12 changes: 0 additions & 12 deletions packages/edit-site/src/store/constants.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* The identifier for the data store.
*
Expand All @@ -14,10 +9,3 @@ export const TEMPLATE_PART_AREA_HEADER = 'header';
export const TEMPLATE_PART_AREA_FOOTER = 'footer';
export const TEMPLATE_PART_AREA_SIDEBAR = 'sidebar';
export const TEMPLATE_PART_AREA_GENERAL = 'uncategorized';

export const TEMPLATE_PART_AREA_TO_NAME = {
[ TEMPLATE_PART_AREA_HEADER ]: __( 'Header' ),
[ TEMPLATE_PART_AREA_FOOTER ]: __( 'Footer' ),
[ TEMPLATE_PART_AREA_SIDEBAR ]: __( 'Sidebar' ),
[ TEMPLATE_PART_AREA_GENERAL ]: __( 'General' ),
};