From 0fcb5b9d8b8d7811ded6a5e55f8a239ce4099969 Mon Sep 17 00:00:00 2001 From: Tom Usborne Date: Tue, 17 Dec 2024 15:37:27 -0500 Subject: [PATCH] Fix: Loop item bugs --- src/blocks/loop-item/block.json | 1 + src/blocks/loop-item/edit.js | 6 +++++- src/blocks/loop-item/editor.scss | 3 +++ src/blocks/looper/components/LoopInnerBlocksRenderer.jsx | 2 ++ 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/blocks/loop-item/editor.scss diff --git a/src/blocks/loop-item/block.json b/src/blocks/loop-item/block.json index 953e9d3d5..676a157b7 100644 --- a/src/blocks/loop-item/block.json +++ b/src/blocks/loop-item/block.json @@ -58,6 +58,7 @@ "generateblocks/loopIndex", "generateblocks/loopItem", "generateblocks/loopPreviewId", + "generateblocks/hasLoopItems", "postId" ] } diff --git a/src/blocks/loop-item/edit.js b/src/blocks/loop-item/edit.js index f710f58e2..6fcc8be3c 100644 --- a/src/blocks/loop-item/edit.js +++ b/src/blocks/loop-item/edit.js @@ -13,6 +13,8 @@ import { BlockStylesBuilder, BlockAppender } from '@components/index'; import { withHtmlAttributes } from '@hoc/withHtmlAttributes.js'; import { getBlockClasses } from '@utils/getBlockClasses'; +import './editor.scss'; + function EditBlock( props ) { const { attributes, @@ -49,6 +51,7 @@ function EditBlock( props ) { if ( isBlockPreview ) { classNames.push( 'gb-block-preview' ); } + const blockProps = useBlockProps( { className: classNames.join( ' ' ).trim(), ...editorHtmlAttributes, @@ -105,6 +108,7 @@ function EditBlock( props ) { const contextPostId = context?.postId ?? context?.[ 'generateblocks/loopIndex' ] ?? 0; const previewId = context?.[ 'generateblocks/loopPreviewId' ] ?? 0; + const hasLoopItems = context?.[ 'generateblocks/hasLoopItems' ] ?? false; return ( <> @@ -128,7 +132,7 @@ function EditBlock( props ) { { innerBlocksChildren } - { previewId !== contextPostId && ( + { !! hasLoopItems && previewId !== contextPostId && (