Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map block: Do not render the actual map if in block preview mode #39768

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Map block: Use block editor store preview flag to determine whether or not to display the placeholder
20 changes: 17 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,14 +236,15 @@ const MapEdit = ( {

let content;

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

content = (
<div>
<img
alt={ __( 'Map Preview', 'jetpack' ) }
src={ mapStyleObject ? mapStyleObject.preview : previewPlaceholder }
style={ { width: '100%', maxHeight: '400px', objectFit: 'cover' } }
/>
</div>
);
Expand Down
Loading