Skip to content

Commit

Permalink
Map block: Use block editor store preview flag to determine whether o…
Browse files Browse the repository at this point in the history
…r not to display the placeholder
  • Loading branch information
zaguiini committed Oct 14, 2024
1 parent 9fac3d5 commit fd0fb68
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions projects/plugins/jetpack/extensions/blocks/map/edit.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -223,7 +236,7 @@ const MapEdit = ( {

let content;

if ( preview ) {
if ( preview || isPreviewMode ) {
const mapStyleObject = styles.find( styleObject => styleObject.name === mapStyle );

content = (
Expand Down

0 comments on commit fd0fb68

Please sign in to comment.