Skip to content

Commit

Permalink
Also change the way we replace template parts from the sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Mar 14, 2024
1 parent 0f54e51 commit 43b55f7
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions packages/block-library/src/template-part/edit/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* WordPress dependencies
*/
import { serialize } from '@wordpress/blocks';
import { useSelect, useDispatch } from '@wordpress/data';
import {
BlockSettingsMenuControls,
Expand Down Expand Up @@ -94,6 +95,7 @@ export default function TemplatePartEdit( {
clientId,
} ) {
const { createSuccessNotice } = useDispatch( noticesStore );
const { editEntityRecord } = useDispatch( coreStore );
const currentTheme = useSelect(
( select ) => select( coreStore ).getCurrentTheme()?.stylesheet,
[]
Expand Down Expand Up @@ -196,12 +198,17 @@ export default function TemplatePartEdit( {
mapTemplatePartToBlockPattern( templatePart )
);

const onTemplatePartSelect = ( templatePart ) => {
setAttributes( {
slug: templatePart.slug,
theme: templatePart.theme,
area: undefined,
} );
const onTemplatePartSelect = async ( templatePart ) => {
await editEntityRecord(
'postType',
'wp_template_part',
templatePartId,
{
blocks: templatePart.blocks,
content: serialize( templatePart.blocks ),
}
);

createSuccessNotice(
sprintf(
/* translators: %s: template part title. */
Expand Down Expand Up @@ -276,9 +283,7 @@ export default function TemplatePartEdit( {
<TemplatesList
availableTemplates={ partsAsPatterns }
onSelect={ ( pattern ) => {
onTemplatePartSelect(
pattern.templatePart
);
onTemplatePartSelect( pattern );
} }
/>
<TemplatesList
Expand Down

0 comments on commit 43b55f7

Please sign in to comment.