Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
fix regression
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed May 10, 2023
1 parent 4737fdb commit b986324
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
8 changes: 6 additions & 2 deletions assets/js/blocks/classic-template/archive-product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ const getButtonLabel = () =>
const onClickCallback = ( {
clientId,
attributes,
blocks,
getBlocks,
replaceBlock,
selectBlock,
}: OnClickCallbackParameter ) => {
replaceBlock( clientId, getBlockifiedTemplate( attributes ) );

const blocks = getBlocks();

const groupBlock = blocks.find(
( block ) =>
block.name === 'core/group' &&
Expand All @@ -124,12 +126,14 @@ const onClickCallback = ( {
const onClickCallbackWithTermDescription = ( {
clientId,
attributes,
blocks,
getBlocks,
replaceBlock,
selectBlock,
}: OnClickCallbackParameter ) => {
replaceBlock( clientId, getBlockifiedTemplate( attributes, true ) );

const blocks = getBlocks();

const groupBlock = blocks.find(
( block ) =>
block.name === 'core/group' &&
Expand Down
12 changes: 8 additions & 4 deletions assets/js/blocks/classic-template/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ const Edit = ( {
const { replaceBlock, selectBlock, replaceBlocks } =
useDispatch( blockEditorStore );

const { blocks, editedPostId } = useSelect( ( sel ) => {
const { getBlocks, editedPostId } = useSelect( ( sel ) => {
return {
blocks: sel( blockEditorStore ).getBlocks(),
getBlocks: sel( blockEditorStore ).getBlocks,
editedPostId: sel( 'core/edit-site' ).getEditedPostId(),
};
}, [] );
Expand All @@ -100,7 +100,11 @@ const Edit = ( {

const { createInfoNotice } = useDispatch( noticesStore );

const clientIds = useMemo( () => pickBlockClientIds( blocks ), [ blocks ] );
const blocks = getBlocks();

const clientIds = useMemo( () => {
pickBlockClientIds( blocks );
}, [ blocks ] );

const blockProps = useBlockProps();
const templateDetails = getTemplateDetailsBySlug(
Expand Down Expand Up @@ -155,7 +159,7 @@ const Edit = ( {
onClick={ () => {
onClickCallback( {
clientId,
blocks,
getBlocks,
attributes,
replaceBlock,
selectBlock,
Expand Down
4 changes: 3 additions & 1 deletion assets/js/blocks/classic-template/product-search-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,14 @@ const getDescription = ( templateTitle: string, canConvert: boolean ) => {
const onClickCallback = ( {
clientId,
attributes,
blocks,
getBlocks,
replaceBlock,
selectBlock,
}: OnClickCallbackParameter ) => {
replaceBlock( clientId, getBlockifiedTemplate( attributes ) );

const blocks = getBlocks();

const groupBlock = blocks.find(
( block ) =>
block.name === 'core/group' &&
Expand Down
3 changes: 2 additions & 1 deletion assets/js/blocks/classic-template/single-product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ const getButtonLabel = () =>

const onClickCallback = ( {
clientId,
blocks,
getBlocks,
replaceBlock,
selectBlock,
}: OnClickCallbackParameter ) => {
replaceBlock( clientId, getBlockifiedTemplate() );

const blocks = getBlocks();
const groupBlock = blocks.find(
( block ) =>
block.name === 'core/group' &&
Expand Down
2 changes: 1 addition & 1 deletion assets/js/blocks/classic-template/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type InheritedAttributes = {
export type OnClickCallbackParameter = {
clientId: string;
attributes: Record< string, unknown >;
blocks: BlockInstance[];
getBlocks: () => BlockInstance[];
replaceBlock: ( clientId: string, blocks: BlockInstance[] ) => void;
selectBlock: ( clientId: string ) => void;
};
Expand Down

0 comments on commit b986324

Please sign in to comment.