From fd0fb68893914b046ea7af835d90337b57ac254e Mon Sep 17 00:00:00 2001 From: Luis Felipe Zaguini Date: Mon, 14 Oct 2024 17:28:47 -0300 Subject: [PATCH] Map block: Use block editor store preview flag to determine whether or not to display the placeholder --- .../jetpack/extensions/blocks/map/edit.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/projects/plugins/jetpack/extensions/blocks/map/edit.js b/projects/plugins/jetpack/extensions/blocks/map/edit.js index e5758c3475e1f..f0dbb3d370558 100644 --- a/projects/plugins/jetpack/extensions/blocks/map/edit.js +++ b/projects/plugins/jetpack/extensions/blocks/map/edit.js @@ -1,6 +1,11 @@ import { getBlockIconComponent } from '@automattic/jetpack-shared-extension-utils'; import apiFetch from '@wordpress/api-fetch'; -import { BlockControls, InspectorControls, useBlockProps } from '@wordpress/block-editor'; +import { + BlockControls, + InspectorControls, + useBlockProps, + store as blockEditorStore, +} from '@wordpress/block-editor'; import { Button, ExternalLink, @@ -10,7 +15,7 @@ import { ResizableBox, } from '@wordpress/components'; import { compose } from '@wordpress/compose'; -import { withDispatch } from '@wordpress/data'; +import { withDispatch, useSelect } from '@wordpress/data'; import { useEffect, useRef, useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { getActiveStyleName } from '../../shared/block-styles'; @@ -67,6 +72,14 @@ const MapEdit = ( { showFullscreenButton, } = attributes; + const { isPreviewMode } = useSelect( select => { + const { getSettings } = select( blockEditorStore ); + const settings = getSettings(); + return { + isPreviewMode: settings.__unstableIsPreviewMode, + }; + }, [] ); + const [ addPointVisibility, setAddPointVisibility ] = useState( false ); const [ apiState, setApiState ] = useState( API_STATE_LOADING ); const [ apiKey, setApiKey ] = useState( null ); @@ -223,7 +236,7 @@ const MapEdit = ( { let content; - if ( preview ) { + if ( preview || isPreviewMode ) { const mapStyleObject = styles.find( styleObject => styleObject.name === mapStyle ); content = (