From 4b00ab085f404f5d44e439f99acb9568f598ad99 Mon Sep 17 00:00:00 2001 From: prconcepcion Date: Tue, 12 Mar 2024 10:26:17 +0800 Subject: [PATCH 01/11] allow dynamic content in map location --- src/block/map/edit.js | 8 ++++++- src/block/map/editor.scss | 16 ++++++++++++++ src/block/map/location-control.js | 36 +++++++++++++++++++++++-------- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/block/map/edit.js b/src/block/map/edit.js index 42c5d73cb5..fe79809916 100644 --- a/src/block/map/edit.js +++ b/src/block/map/edit.js @@ -23,6 +23,7 @@ import { PanelAdvancedSettings, ResizerTooltip, StyleControl, + getDynamicContent, } from '~stackable/components' import { useDeviceType } from '~stackable/hooks' import { @@ -104,6 +105,7 @@ const Edit = props => { const { stackable_google_maps_api_key: apiKey } = settings const userCanManageApiKey = useMemo( () => currentUserHasCapability( 'manage_options' ), [] ) + const mapAddress = address.startsWith( '!#stk_dynamic/' ) ? getDynamicContent( address ) : address // This just forces the tooltip to update. const [ , setResizingHeight ] = useState( '' ) @@ -243,6 +245,9 @@ const Edit = props => { // Try geocoding the address. const [ useGeocoding, setUseGeocoding ] = useState( true ) const geocodeAddress = useCallback( debounce( address => { + if ( address.startsWith( '!#stk_dynamic/' ) ) { + address = getDynamicContent( address ) + } if ( useGeocoding ) { geocoderRef.current.geocode( { address, @@ -291,6 +296,7 @@ const Edit = props => { label={ __( 'Location', i18n ) } attribute="address" placeholder={ __( 'Enter an address or location', i18n ) } + isDynamic={ true } /> ) : ( @@ -537,7 +543,7 @@ const Edit = props => { ) : (