From a7be8809520fce18260ed781dc24f046935e1bae Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Thu, 3 Mar 2022 18:21:38 -0300 Subject: [PATCH] Uses serverSideRender component to display item gallery. #674. --- .../blocks/item-gallery/edit.js | 31 +++++++++---------- .../blocks/item-gallery/save.php | 2 +- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/views/gutenberg-blocks/blocks/item-gallery/edit.js b/src/views/gutenberg-blocks/blocks/item-gallery/edit.js index ce63ba5ad..15607d790 100644 --- a/src/views/gutenberg-blocks/blocks/item-gallery/edit.js +++ b/src/views/gutenberg-blocks/blocks/item-gallery/edit.js @@ -2,7 +2,7 @@ const { __ } = wp.i18n; const { Button, Placeholder, ToggleControl, PanelBody } = wp.components; -const { serverSideRender: ServerSideRender } = wp.serverSideRender; +const ServerSideRender = wp.serverSideRender; const { InspectorControls, useBlockProps } = (tainacan_blocks.wp_version < '5.2' ? wp.editor : wp.blockEditor ); import SingleItemModal from '../../js/selection/single-item-modal.js'; @@ -10,7 +10,6 @@ import SingleItemModal from '../../js/selection/single-item-modal.js'; export default function ({ attributes, setAttributes, className, isSelected, clientId }) { let { - blockId, content, collectionId, itemId, @@ -35,13 +34,6 @@ export default function ({ attributes, setAttributes, className, isSelected, cli // Obtains block's client id to render it on save function setAttributes({ blockId: clientId }); - function openSingleItemModal() { - isModalOpen = true; - setAttributes( { - isModalOpen: isModalOpen - }); - } - return content == 'preview' ?
openSingleItemModal() }> + onClick={ () => { + isModalOpen = true; + setAttributes( { + isModalOpen: isModalOpen + }); + } + }> {__('Select Item', 'tainacan')} @@ -286,13 +284,12 @@ export default function ({ attributes, setAttributes, className, isSelected, cli } { itemId ? ( - -
- { JSON.stringify(attributes) } - {/* */} -
+
+ +
) : null } diff --git a/src/views/gutenberg-blocks/blocks/item-gallery/save.php b/src/views/gutenberg-blocks/blocks/item-gallery/save.php index 6a6228df4..8de3ecfd8 100644 --- a/src/views/gutenberg-blocks/blocks/item-gallery/save.php +++ b/src/views/gutenberg-blocks/blocks/item-gallery/save.php @@ -10,7 +10,7 @@ function tainacan_blocks_render_items_gallery( $block_attributes, $content ) { if ( !isset($block_attributes['itemId']) ) return ''; - + // Gets options from block attributes $item_id = $block_attributes['itemId']; $block_id = $block_attributes['blockId'];