@yext/visual-editor 2.0.0-beta.11 → 2.0.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{SectionLibraryVisualEditorProvider-DJMXab-H.js → SectionLibraryVisualEditorProvider-64whofF8.js} +5861 -5761
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Filters.test.tsx +1 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Filters.tsx +9 -8
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Locator.test.tsx +1 -1
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Locator.tsx +104 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorFields.test.ts +66 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorRadius.test.ts +700 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorResultCard.tsx +29 -1
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorWrapper.test.ts +370 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorWrapper.tsx +270 -39
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Map.tsx +91 -12
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Results.tsx +11 -6
- package/dist/cli/assets/directory-locator-source/components/sections/locator/distanceUnits.ts +7 -0
- package/dist/cli/assets/directory-locator-source/sectionLibrarySupport.ts +4 -0
- package/dist/cli/yextve.js +3 -3
- package/dist/{createYextFieldTransforms-B7vqqb3m.d.ts → createYextFieldTransforms-w-U4b5Zf.d.ts} +27 -17
- package/dist/index.d.ts +36 -11
- package/dist/locales/platform/cs/visual-editor.json +10 -0
- package/dist/locales/platform/da/visual-editor.json +10 -0
- package/dist/locales/platform/de/visual-editor.json +10 -0
- package/dist/locales/platform/en/visual-editor.json +10 -0
- package/dist/locales/platform/en-GB/visual-editor.json +10 -0
- package/dist/locales/platform/es/visual-editor.json +10 -0
- package/dist/locales/platform/et/visual-editor.json +10 -0
- package/dist/locales/platform/fi/visual-editor.json +10 -0
- package/dist/locales/platform/fr/visual-editor.json +10 -0
- package/dist/locales/platform/hr/visual-editor.json +10 -0
- package/dist/locales/platform/hu/visual-editor.json +10 -0
- package/dist/locales/platform/it/visual-editor.json +10 -0
- package/dist/locales/platform/ja/visual-editor.json +10 -0
- package/dist/locales/platform/lt/visual-editor.json +10 -0
- package/dist/locales/platform/lv/visual-editor.json +10 -0
- package/dist/locales/platform/nb/visual-editor.json +10 -0
- package/dist/locales/platform/nl/visual-editor.json +10 -0
- package/dist/locales/platform/pl/visual-editor.json +10 -0
- package/dist/locales/platform/pt/visual-editor.json +10 -0
- package/dist/locales/platform/ro/visual-editor.json +10 -0
- package/dist/locales/platform/sk/visual-editor.json +10 -0
- package/dist/locales/platform/sv/visual-editor.json +10 -0
- package/dist/locales/platform/tr/visual-editor.json +10 -0
- package/dist/locales/platform/zh/visual-editor.json +10 -0
- package/dist/locales/platform/zh-TW/visual-editor.json +10 -0
- package/dist/plugin/plugin.js +2 -1
- package/dist/plugin/vite-plugin/layout-generation/modelProxy.d.ts +1 -1
- package/dist/section-library-support.js +67 -67
- package/dist/sectionLibrarySupport.d.ts +2 -2
- package/dist/{visual-editor-DTE5kxrA.js → visual-editor-B84T0Hz5.js} +84 -74
- package/dist/{visual-editor-6mKs9VUe.js → visual-editor-B8eVGZjZ.js} +26 -16
- package/dist/{visual-editor-Bs3wAslG.js → visual-editor-BTv1Bren.js} +62 -52
- package/dist/{visual-editor-DkHhrFsX.js → visual-editor-BWJvQ6QT.js} +110 -100
- package/dist/{visual-editor-D7VeTRK_.js → visual-editor-BWk-Ri1i.js} +73 -63
- package/dist/{visual-editor-LXMNWXry.js → visual-editor-BdM7VUac.js} +76 -66
- package/dist/{visual-editor-ClC6hoz3.js → visual-editor-BmM2bYhg.js} +82 -72
- package/dist/{visual-editor-qJW0uCiQ.js → visual-editor-BuRftlWt.js} +89 -79
- package/dist/{visual-editor-DjTEbi-1.js → visual-editor-BxnbtD_z.js} +63 -53
- package/dist/{visual-editor-CcfUKpnd.js → visual-editor-C4Nretnd.js} +59 -49
- package/dist/{visual-editor-Duishbsa.js → visual-editor-CFE4ijeV.js} +54 -44
- package/dist/{visual-editor-DtL-Zuv_.js → visual-editor-CMfDvLU2.js} +86 -76
- package/dist/{visual-editor-BK6fTU7k.js → visual-editor-CauX7_Ur.js} +27 -17
- package/dist/{visual-editor-QpGupjY5.js → visual-editor-D5d9meOo.js} +93 -83
- package/dist/{visual-editor-gEaWoNRu.js → visual-editor-D9U8TxD-.js} +51 -41
- package/dist/{visual-editor-CtQwadxQ.js → visual-editor-DBZwjDQd.js} +47 -37
- package/dist/{visual-editor-_TatCCAS.js → visual-editor-DI6rS2dP.js} +116 -106
- package/dist/{visual-editor-sOPDMkOR.js → visual-editor-DOioJ5CW.js} +84 -74
- package/dist/{visual-editor-zKhC7_0C.js → visual-editor-D_EvXM08.js} +71 -61
- package/dist/{visual-editor-BruRrJYN.js → visual-editor-DguhAL12.js} +10 -0
- package/dist/{visual-editor-CHWtMtlu.js → visual-editor-DmsRSmAI.js} +90 -80
- package/dist/{visual-editor-vomNdlNO.js → visual-editor-DnNNHiLS.js} +86 -76
- package/dist/{visual-editor-C9TLeAzP.js → visual-editor-DvksDrGT.js} +59 -49
- package/dist/{visual-editor-tPb7n5l8.js → visual-editor-XsBMHUSs.js} +66 -56
- package/dist/{visual-editor-gjpr-NAN.js → visual-editor-kiT3ocKi.js} +60 -50
- package/dist/visual-editor.css +1 -1
- package/dist/visual-editor.js +7003 -6609
- package/package.json +3 -3
package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorWrapper.tsx
CHANGED
|
@@ -37,7 +37,7 @@ import { resolveLocalizedAssetImage } from "../../../types/images.ts";
|
|
|
37
37
|
import {
|
|
38
38
|
getPreferredDistanceUnit,
|
|
39
39
|
toMeters,
|
|
40
|
-
|
|
40
|
+
fromMeters,
|
|
41
41
|
} from "../../../utils/i18n/distance.ts";
|
|
42
42
|
import { resolveComponentData } from "../../../utils/resolveComponentData.tsx";
|
|
43
43
|
import {
|
|
@@ -48,6 +48,12 @@ import { getThemeColorCssValue } from "../../../utils/colors.ts";
|
|
|
48
48
|
import { Button } from "../../atoms/button.tsx";
|
|
49
49
|
import { Body } from "../../atoms/body.tsx";
|
|
50
50
|
import { Heading } from "../../atoms/heading.tsx";
|
|
51
|
+
import {
|
|
52
|
+
BROWSER_LANGUAGE,
|
|
53
|
+
DISTANCE_UNITS,
|
|
54
|
+
MILE,
|
|
55
|
+
type DistanceUnit,
|
|
56
|
+
} from "./distanceUnits.ts";
|
|
51
57
|
import {
|
|
52
58
|
DEFAULT_ENTITY_TYPE,
|
|
53
59
|
LocatorEntityType,
|
|
@@ -85,6 +91,7 @@ import {
|
|
|
85
91
|
ResultsCountSummary,
|
|
86
92
|
RESULTS_LIMIT,
|
|
87
93
|
SearchState,
|
|
94
|
+
translateDistanceUnit,
|
|
88
95
|
} from "./Results.tsx";
|
|
89
96
|
|
|
90
97
|
export const INITIAL_LOCATION_KEY = "initialLocation";
|
|
@@ -158,6 +165,7 @@ export const LocatorWrapper = (props: WithPuckProps<LocatorProps>) => {
|
|
|
158
165
|
};
|
|
159
166
|
|
|
160
167
|
const LocatorInternal = ({
|
|
168
|
+
autoSearchOnMapMove = false,
|
|
161
169
|
mapStyle,
|
|
162
170
|
locationStyles,
|
|
163
171
|
filters: {
|
|
@@ -168,8 +176,11 @@ const LocatorInternal = ({
|
|
|
168
176
|
keywordsDisplayName,
|
|
169
177
|
},
|
|
170
178
|
mapStartingLocation,
|
|
179
|
+
defaultSearchRadius,
|
|
171
180
|
resultCard: resultCardConfigs,
|
|
172
181
|
distanceDisplay,
|
|
182
|
+
showDistanceUnitToggle,
|
|
183
|
+
defaultDistanceUnit,
|
|
173
184
|
pageHeading,
|
|
174
185
|
}: LocatorProps) => {
|
|
175
186
|
// Adds unified [enable|disable]YextAnalytics to the window for both Pages and Search
|
|
@@ -197,6 +208,23 @@ const LocatorInternal = ({
|
|
|
197
208
|
const windowWidth = useWindowWidth(previewWindow);
|
|
198
209
|
const { isMobile } = getViewport(windowWidth);
|
|
199
210
|
const preferredUnit = getPreferredDistanceUnit(i18n.language);
|
|
211
|
+
const [distanceUnitOverride, setDistanceUnitOverride] =
|
|
212
|
+
React.useState<DistanceUnit | null>(null);
|
|
213
|
+
const configuredDistanceUnit =
|
|
214
|
+
defaultDistanceUnit && defaultDistanceUnit !== BROWSER_LANGUAGE
|
|
215
|
+
? defaultDistanceUnit
|
|
216
|
+
: preferredUnit;
|
|
217
|
+
const distanceUnit = distanceUnitOverride ?? configuredDistanceUnit;
|
|
218
|
+
React.useEffect(() => setDistanceUnitOverride(null), [defaultDistanceUnit]);
|
|
219
|
+
// Puck emits 0 when its number field is cleared; only positive radii override Search.
|
|
220
|
+
const configuredRadiusMeters =
|
|
221
|
+
defaultSearchRadius?.value && defaultSearchRadius.value > 0
|
|
222
|
+
? toMeters(defaultSearchRadius.value, defaultSearchRadius.unit)
|
|
223
|
+
: undefined;
|
|
224
|
+
const defaultRadiusMeters =
|
|
225
|
+
configuredRadiusMeters ?? toMeters(DEFAULT_RADIUS, distanceUnit);
|
|
226
|
+
const initialDefaultRadiusMeters =
|
|
227
|
+
configuredRadiusMeters ?? toMeters(DEFAULT_RADIUS, configuredDistanceUnit);
|
|
200
228
|
const streamDocument = useDocument();
|
|
201
229
|
const entityTypeSourceMap = getLocatorEntityTypeSourceMap(streamDocument);
|
|
202
230
|
const entityTypes =
|
|
@@ -243,6 +271,11 @@ const LocatorInternal = ({
|
|
|
243
271
|
const [showSearchAreaButton, setShowSearchAreaButton] = React.useState(false);
|
|
244
272
|
const [mapCenter, setMapCenter] = React.useState<Coordinate | undefined>();
|
|
245
273
|
const [mapRadius, setMapRadius] = React.useState<number | undefined>();
|
|
274
|
+
const mapSearchTimeout = React.useRef<ReturnType<typeof setTimeout>>();
|
|
275
|
+
const cancelMapSearch = React.useCallback((): void => {
|
|
276
|
+
clearTimeout(mapSearchTimeout.current);
|
|
277
|
+
mapSearchTimeout.current = undefined;
|
|
278
|
+
}, []);
|
|
246
279
|
/** Explicit filter radius selected by the user, in meters */
|
|
247
280
|
const [selectedDistanceMeters, setSelectedDistanceMeters] = React.useState<
|
|
248
281
|
number | null
|
|
@@ -250,8 +283,16 @@ const LocatorInternal = ({
|
|
|
250
283
|
const [selectedDistanceOption, setSelectedDistanceOption] = React.useState<
|
|
251
284
|
number | null
|
|
252
285
|
>(null);
|
|
286
|
+
const currentDistanceSelection = React.useRef({
|
|
287
|
+
selectedDistanceOption,
|
|
288
|
+
distanceUnit,
|
|
289
|
+
});
|
|
290
|
+
currentDistanceSelection.current = { selectedDistanceOption, distanceUnit };
|
|
291
|
+
const previousDistanceUnit = React.useRef(distanceUnit);
|
|
253
292
|
/** Radius of the current location filter before a distance option is applied */
|
|
254
|
-
const
|
|
293
|
+
const baseFilterRadius = React.useRef<number | null>(null);
|
|
294
|
+
/** Minimum accuracy for a base radius derived from the default unit; null for independent radii. */
|
|
295
|
+
const automaticBaseRadiusAccuracy = React.useRef<number | null>(null);
|
|
255
296
|
|
|
256
297
|
const handleDrag: OnDragHandler = (center, bounds) => {
|
|
257
298
|
setMapCenter({
|
|
@@ -260,6 +301,13 @@ const LocatorInternal = ({
|
|
|
260
301
|
});
|
|
261
302
|
setMapRadius(center.distanceTo(bounds.getNorthEast()));
|
|
262
303
|
setShowSearchAreaButton(true);
|
|
304
|
+
cancelMapSearch();
|
|
305
|
+
if (autoSearchOnMapMove && mapEnabled) {
|
|
306
|
+
mapSearchTimeout.current = setTimeout((): void => {
|
|
307
|
+
mapSearchTimeout.current = undefined;
|
|
308
|
+
searchMapArea.current();
|
|
309
|
+
}, 500);
|
|
310
|
+
}
|
|
263
311
|
};
|
|
264
312
|
|
|
265
313
|
const [isOpenNowSelected, setIsOpenNowSelected] = React.useState(false);
|
|
@@ -280,7 +328,10 @@ const LocatorInternal = ({
|
|
|
280
328
|
const searchActions = useSearchActions();
|
|
281
329
|
const searchFilters = useSearchState((state) => state.filters);
|
|
282
330
|
|
|
283
|
-
const
|
|
331
|
+
const preserveMapView = React.useRef(false);
|
|
332
|
+
|
|
333
|
+
const handleSearchAreaClick = (preserveView = false): void => {
|
|
334
|
+
cancelMapSearch();
|
|
284
335
|
if (mapCenter && mapRadius) {
|
|
285
336
|
searchActions.setOffset(0);
|
|
286
337
|
const locationFilter: SelectableStaticFilter = {
|
|
@@ -298,8 +349,12 @@ const LocatorInternal = ({
|
|
|
298
349
|
matcher: Matcher.Near,
|
|
299
350
|
},
|
|
300
351
|
};
|
|
301
|
-
|
|
352
|
+
baseFilterRadius.current = mapRadius;
|
|
353
|
+
automaticBaseRadiusAccuracy.current = null;
|
|
354
|
+
setSelectedDistanceOption(null);
|
|
355
|
+
setSelectedDistanceMeters(null);
|
|
302
356
|
searchActions.setStaticFilters([locationFilter, openNowFilter]);
|
|
357
|
+
preserveMapView.current = preserveView;
|
|
303
358
|
searchActions.executeVerticalQuery();
|
|
304
359
|
setSearchState("loading");
|
|
305
360
|
setShowSearchAreaButton(false);
|
|
@@ -314,16 +369,30 @@ const LocatorInternal = ({
|
|
|
314
369
|
}
|
|
315
370
|
};
|
|
316
371
|
|
|
372
|
+
const searchMapArea = React.useRef((): void => handleSearchAreaClick(true));
|
|
373
|
+
React.useEffect((): void => {
|
|
374
|
+
// Use the current map area and filters when the movement delay ends.
|
|
375
|
+
searchMapArea.current = (): void => handleSearchAreaClick(true);
|
|
376
|
+
});
|
|
377
|
+
|
|
317
378
|
const handleCurrentLocationClick = (position: GeolocationPosition) => {
|
|
379
|
+
cancelMapSearch();
|
|
380
|
+
setShowSearchAreaButton(false);
|
|
318
381
|
const { latitude, longitude, accuracy } = position.coords;
|
|
319
|
-
|
|
382
|
+
baseFilterRadius.current = Math.max(accuracy, defaultRadiusMeters);
|
|
383
|
+
automaticBaseRadiusAccuracy.current = accuracy;
|
|
384
|
+
const radius = Math.max(
|
|
385
|
+
accuracy,
|
|
386
|
+
showDistanceOptions && selectedDistanceMeters
|
|
387
|
+
? selectedDistanceMeters
|
|
388
|
+
: defaultRadiusMeters
|
|
389
|
+
);
|
|
320
390
|
const locationFilter = buildNearLocationFilterFromCoords(
|
|
321
391
|
latitude,
|
|
322
392
|
longitude,
|
|
323
393
|
radius,
|
|
324
394
|
t("currentLocation", "Current Location")
|
|
325
395
|
);
|
|
326
|
-
apiFilterRadius.current = radius;
|
|
327
396
|
const nonLocationFilters = (searchFilters.static || []).filter(
|
|
328
397
|
(staticFilter) =>
|
|
329
398
|
staticFilter.filter.kind !== "fieldValue" ||
|
|
@@ -333,6 +402,7 @@ const LocatorInternal = ({
|
|
|
333
402
|
);
|
|
334
403
|
searchActions.setOffset(0);
|
|
335
404
|
searchActions.setStaticFilters([...nonLocationFilters, locationFilter]);
|
|
405
|
+
preserveMapView.current = false;
|
|
336
406
|
searchActions.executeVerticalQuery();
|
|
337
407
|
setSearchState("loading");
|
|
338
408
|
updateLocationQuery(formatCoordinateQuery(latitude, longitude, radius));
|
|
@@ -361,6 +431,8 @@ const LocatorInternal = ({
|
|
|
361
431
|
);
|
|
362
432
|
|
|
363
433
|
const handleFilterSelect = (params: OnSelectParams) => {
|
|
434
|
+
cancelMapSearch();
|
|
435
|
+
setShowSearchAreaButton(false);
|
|
364
436
|
const newDisplayName = params.newDisplayName;
|
|
365
437
|
const filter = params.newFilter;
|
|
366
438
|
|
|
@@ -369,12 +441,13 @@ const LocatorInternal = ({
|
|
|
369
441
|
switch (filter.matcher) {
|
|
370
442
|
case Matcher.Near: {
|
|
371
443
|
nearFilterValue = filter.value as NearFilterValue;
|
|
372
|
-
|
|
373
|
-
|
|
444
|
+
baseFilterRadius.current =
|
|
445
|
+
configuredRadiusMeters ?? nearFilterValue.radius;
|
|
446
|
+
automaticBaseRadiusAccuracy.current = null;
|
|
374
447
|
const radius =
|
|
375
448
|
showDistanceOptions && selectedDistanceMeters
|
|
376
449
|
? selectedDistanceMeters
|
|
377
|
-
:
|
|
450
|
+
: baseFilterRadius.current;
|
|
378
451
|
locationFilter = buildNearLocationFilterFromPrevious(
|
|
379
452
|
nearFilterValue,
|
|
380
453
|
newDisplayName,
|
|
@@ -383,7 +456,8 @@ const LocatorInternal = ({
|
|
|
383
456
|
break;
|
|
384
457
|
}
|
|
385
458
|
case Matcher.Equals: {
|
|
386
|
-
|
|
459
|
+
baseFilterRadius.current = null;
|
|
460
|
+
automaticBaseRadiusAccuracy.current = null;
|
|
387
461
|
locationFilter = buildEqualsLocationFilter(filter, newDisplayName);
|
|
388
462
|
break;
|
|
389
463
|
}
|
|
@@ -394,6 +468,7 @@ const LocatorInternal = ({
|
|
|
394
468
|
|
|
395
469
|
searchActions.setOffset(0);
|
|
396
470
|
searchActions.setStaticFilters([locationFilter, openNowFilter]);
|
|
471
|
+
preserveMapView.current = false;
|
|
397
472
|
searchActions.executeVerticalQuery();
|
|
398
473
|
setSearchState("loading");
|
|
399
474
|
updateLocationQuery(newDisplayName);
|
|
@@ -407,7 +482,11 @@ const LocatorInternal = ({
|
|
|
407
482
|
latitude: nearFilterValue.lat,
|
|
408
483
|
longitude: nearFilterValue.lng,
|
|
409
484
|
});
|
|
410
|
-
setMapRadius(
|
|
485
|
+
setMapRadius(
|
|
486
|
+
showDistanceOptions && selectedDistanceMeters
|
|
487
|
+
? selectedDistanceMeters
|
|
488
|
+
: (baseFilterRadius.current ?? nearFilterValue.radius)
|
|
489
|
+
);
|
|
411
490
|
}
|
|
412
491
|
};
|
|
413
492
|
|
|
@@ -424,13 +503,39 @@ const LocatorInternal = ({
|
|
|
424
503
|
}, [searchLoading, searchState]);
|
|
425
504
|
|
|
426
505
|
React.useEffect(() => {
|
|
506
|
+
const unitChanged = previousDistanceUnit.current !== distanceUnit;
|
|
507
|
+
previousDistanceUnit.current = distanceUnit;
|
|
508
|
+
if (unitChanged && automaticBaseRadiusAccuracy.current !== null) {
|
|
509
|
+
baseFilterRadius.current = Math.max(
|
|
510
|
+
automaticBaseRadiusAccuracy.current,
|
|
511
|
+
defaultRadiusMeters
|
|
512
|
+
);
|
|
513
|
+
}
|
|
427
514
|
if (selectedDistanceOption === null) {
|
|
428
515
|
setSelectedDistanceMeters(null);
|
|
429
516
|
return;
|
|
430
517
|
}
|
|
431
518
|
|
|
432
|
-
|
|
433
|
-
|
|
519
|
+
const radius = toMeters(selectedDistanceOption, distanceUnit);
|
|
520
|
+
setSelectedDistanceMeters(radius);
|
|
521
|
+
if (unitChanged) {
|
|
522
|
+
const updatedFilters = updateRadiusInNearFiltersOnLocationField(
|
|
523
|
+
searchFilters.static || [],
|
|
524
|
+
radius
|
|
525
|
+
);
|
|
526
|
+
searchActions.setStaticFilters(updatedFilters);
|
|
527
|
+
searchActions.setOffset(0);
|
|
528
|
+
preserveMapView.current = false;
|
|
529
|
+
executeSearch(searchActions);
|
|
530
|
+
setSearchState("loading");
|
|
531
|
+
}
|
|
532
|
+
}, [
|
|
533
|
+
distanceUnit,
|
|
534
|
+
defaultRadiusMeters,
|
|
535
|
+
selectedDistanceOption,
|
|
536
|
+
searchActions,
|
|
537
|
+
searchFilters.static,
|
|
538
|
+
]);
|
|
434
539
|
|
|
435
540
|
const resultsRef = React.useRef<Array<HTMLDivElement | null>>([]);
|
|
436
541
|
const resultsContainer = React.useRef<HTMLDivElement>(null);
|
|
@@ -518,12 +623,14 @@ const LocatorInternal = ({
|
|
|
518
623
|
resultCardProps={resultCardProps}
|
|
519
624
|
isSelected={result.result.index === selectedResultIndex}
|
|
520
625
|
distanceDisplay={distanceDisplay}
|
|
626
|
+
distanceUnit={distanceUnit}
|
|
521
627
|
searchLocationName={filterDisplayName}
|
|
522
628
|
/>
|
|
523
629
|
);
|
|
524
630
|
},
|
|
525
631
|
[
|
|
526
632
|
distanceDisplay,
|
|
633
|
+
distanceUnit,
|
|
527
634
|
filterDisplayName,
|
|
528
635
|
getResultCardProps,
|
|
529
636
|
selectedResultIndex,
|
|
@@ -577,6 +684,7 @@ const LocatorInternal = ({
|
|
|
577
684
|
const mapProps = React.useMemo(
|
|
578
685
|
() => ({
|
|
579
686
|
mapStyle,
|
|
687
|
+
preserveMapView,
|
|
580
688
|
centerCoords,
|
|
581
689
|
onDragHandler: handleDrag,
|
|
582
690
|
scrollToResult,
|
|
@@ -593,8 +701,46 @@ const LocatorInternal = ({
|
|
|
593
701
|
]
|
|
594
702
|
);
|
|
595
703
|
|
|
704
|
+
const initializationInputsRef = React.useRef({
|
|
705
|
+
urlNavigationVersion,
|
|
706
|
+
initialMapCenter,
|
|
707
|
+
searchActions,
|
|
708
|
+
configuredRadiusMeters,
|
|
709
|
+
initialDefaultRadiusMeters,
|
|
710
|
+
});
|
|
711
|
+
const initializationCompleted = React.useRef(false);
|
|
596
712
|
React.useEffect(() => {
|
|
713
|
+
const previousInputs = initializationInputsRef.current;
|
|
714
|
+
initializationInputsRef.current = {
|
|
715
|
+
urlNavigationVersion,
|
|
716
|
+
initialMapCenter,
|
|
717
|
+
searchActions,
|
|
718
|
+
configuredRadiusMeters,
|
|
719
|
+
initialDefaultRadiusMeters,
|
|
720
|
+
};
|
|
721
|
+
// Changing only the default unit should update the active distance filter
|
|
722
|
+
// without restarting location initialization.
|
|
723
|
+
if (
|
|
724
|
+
initializationCompleted.current &&
|
|
725
|
+
selectedDistanceOption !== null &&
|
|
726
|
+
previousInputs.urlNavigationVersion === urlNavigationVersion &&
|
|
727
|
+
previousInputs.initialMapCenter === initialMapCenter &&
|
|
728
|
+
previousInputs.searchActions === searchActions &&
|
|
729
|
+
previousInputs.configuredRadiusMeters === configuredRadiusMeters &&
|
|
730
|
+
previousInputs.initialDefaultRadiusMeters !== initialDefaultRadiusMeters
|
|
731
|
+
) {
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
initializationCompleted.current = false;
|
|
597
736
|
let isCancelled = false;
|
|
737
|
+
const getActiveDistanceMeters = () => {
|
|
738
|
+
const { selectedDistanceOption, distanceUnit } =
|
|
739
|
+
currentDistanceSelection.current;
|
|
740
|
+
return selectedDistanceOption === null
|
|
741
|
+
? null
|
|
742
|
+
: toMeters(selectedDistanceOption, distanceUnit);
|
|
743
|
+
};
|
|
598
744
|
const queryParams = new URLSearchParams(window.location.search);
|
|
599
745
|
const initialLocationParam = queryParams.has(LOCATION_QUERY_KEY)
|
|
600
746
|
? queryParams.get(LOCATION_QUERY_KEY)
|
|
@@ -605,10 +751,13 @@ const LocatorInternal = ({
|
|
|
605
751
|
setCenterCoords(initialMapCenter);
|
|
606
752
|
setMapCenter(initialMapCenter);
|
|
607
753
|
|
|
754
|
+
const activeDistanceMeters = getActiveDistanceMeters();
|
|
608
755
|
const radius =
|
|
609
|
-
showDistanceOptions &&
|
|
610
|
-
?
|
|
611
|
-
:
|
|
756
|
+
showDistanceOptions && activeDistanceMeters
|
|
757
|
+
? activeDistanceMeters
|
|
758
|
+
: initialDefaultRadiusMeters;
|
|
759
|
+
baseFilterRadius.current = initialDefaultRadiusMeters;
|
|
760
|
+
automaticBaseRadiusAccuracy.current = 0;
|
|
612
761
|
// default location filter to configured starting location or NYC
|
|
613
762
|
let initialLocationFilter = buildNearLocationFilterFromCoords(
|
|
614
763
|
initialMapCenter.latitude,
|
|
@@ -626,6 +775,7 @@ const LocatorInternal = ({
|
|
|
626
775
|
? [initialLocationFilter]
|
|
627
776
|
: [initialLocationFilter, openNowFilter]
|
|
628
777
|
);
|
|
778
|
+
preserveMapView.current = false;
|
|
629
779
|
searchActions.executeVerticalQuery();
|
|
630
780
|
setSearchState("loading");
|
|
631
781
|
if (
|
|
@@ -634,7 +784,6 @@ const LocatorInternal = ({
|
|
|
634
784
|
) {
|
|
635
785
|
const filterValue = initialLocationFilter.filter
|
|
636
786
|
.value as NearFilterValue;
|
|
637
|
-
apiFilterRadius.current = filterValue.radius;
|
|
638
787
|
const nextCenterCoords: Coordinate = {
|
|
639
788
|
longitude: filterValue.lng,
|
|
640
789
|
latitude: filterValue.lat,
|
|
@@ -653,6 +802,7 @@ const LocatorInternal = ({
|
|
|
653
802
|
}
|
|
654
803
|
if (!isCancelled) {
|
|
655
804
|
setIsInitialMapLocationResolved(true);
|
|
805
|
+
initializationCompleted.current = true;
|
|
656
806
|
}
|
|
657
807
|
};
|
|
658
808
|
|
|
@@ -680,11 +830,17 @@ const LocatorInternal = ({
|
|
|
680
830
|
switch (resultFilter.matcher) {
|
|
681
831
|
case Matcher.Near: {
|
|
682
832
|
const filterFromResult = resultFilter.value as NearFilterValue;
|
|
833
|
+
baseFilterRadius.current =
|
|
834
|
+
configuredRadiusMeters ?? filterFromResult.radius;
|
|
835
|
+
automaticBaseRadiusAccuracy.current = null;
|
|
836
|
+
const activeDistanceMeters = getActiveDistanceMeters();
|
|
683
837
|
initialLocationFilter = buildNearLocationFilterFromPrevious(
|
|
684
838
|
filterFromResult,
|
|
685
|
-
firstResult.value
|
|
839
|
+
firstResult.value,
|
|
840
|
+
showDistanceOptions && activeDistanceMeters
|
|
841
|
+
? activeDistanceMeters
|
|
842
|
+
: baseFilterRadius.current
|
|
686
843
|
);
|
|
687
|
-
apiFilterRadius.current = filterFromResult.radius;
|
|
688
844
|
return true;
|
|
689
845
|
}
|
|
690
846
|
case Matcher.Equals: {
|
|
@@ -692,7 +848,8 @@ const LocatorInternal = ({
|
|
|
692
848
|
resultFilter,
|
|
693
849
|
firstResult.value
|
|
694
850
|
);
|
|
695
|
-
|
|
851
|
+
baseFilterRadius.current = null;
|
|
852
|
+
automaticBaseRadiusAccuracy.current = null;
|
|
696
853
|
return true;
|
|
697
854
|
}
|
|
698
855
|
default: {
|
|
@@ -712,6 +869,10 @@ const LocatorInternal = ({
|
|
|
712
869
|
? parseCoordinateQuery(initialLocationParam)
|
|
713
870
|
: undefined;
|
|
714
871
|
if (coordinates) {
|
|
872
|
+
baseFilterRadius.current = coordinates.radius;
|
|
873
|
+
automaticBaseRadiusAccuracy.current = null;
|
|
874
|
+
setSelectedDistanceOption(null);
|
|
875
|
+
setSelectedDistanceMeters(null);
|
|
715
876
|
initialLocationFilter = buildNearLocationFilterFromCoords(
|
|
716
877
|
coordinates.lat,
|
|
717
878
|
coordinates.lng,
|
|
@@ -766,14 +927,33 @@ const LocatorInternal = ({
|
|
|
766
927
|
}
|
|
767
928
|
} catch (e) {
|
|
768
929
|
console.warn("Reverse geocoding failed:", e);
|
|
769
|
-
} finally {
|
|
770
|
-
initialLocationFilter = buildNearLocationFilterFromCoords(
|
|
771
|
-
lat,
|
|
772
|
-
lng,
|
|
773
|
-
radius,
|
|
774
|
-
displayName
|
|
775
|
-
);
|
|
776
930
|
}
|
|
931
|
+
if (isCancelled) {
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
const activeDistanceMeters = getActiveDistanceMeters();
|
|
935
|
+
const currentDefaultRadiusMeters =
|
|
936
|
+
configuredRadiusMeters ??
|
|
937
|
+
toMeters(
|
|
938
|
+
DEFAULT_RADIUS,
|
|
939
|
+
currentDistanceSelection.current.distanceUnit
|
|
940
|
+
);
|
|
941
|
+
baseFilterRadius.current = Math.max(
|
|
942
|
+
location.coords.accuracy,
|
|
943
|
+
currentDefaultRadiusMeters
|
|
944
|
+
);
|
|
945
|
+
automaticBaseRadiusAccuracy.current = location.coords.accuracy;
|
|
946
|
+
initialLocationFilter = buildNearLocationFilterFromCoords(
|
|
947
|
+
lat,
|
|
948
|
+
lng,
|
|
949
|
+
Math.max(
|
|
950
|
+
location.coords.accuracy,
|
|
951
|
+
showDistanceOptions && activeDistanceMeters
|
|
952
|
+
? activeDistanceMeters
|
|
953
|
+
: currentDefaultRadiusMeters
|
|
954
|
+
),
|
|
955
|
+
displayName
|
|
956
|
+
);
|
|
777
957
|
} catch {
|
|
778
958
|
// Fall back to configured starting location or default center.
|
|
779
959
|
}
|
|
@@ -790,7 +970,13 @@ const LocatorInternal = ({
|
|
|
790
970
|
return () => {
|
|
791
971
|
isCancelled = true;
|
|
792
972
|
};
|
|
793
|
-
}, [
|
|
973
|
+
}, [
|
|
974
|
+
urlNavigationVersion,
|
|
975
|
+
initialMapCenter,
|
|
976
|
+
searchActions,
|
|
977
|
+
configuredRadiusMeters,
|
|
978
|
+
initialDefaultRadiusMeters,
|
|
979
|
+
]);
|
|
794
980
|
|
|
795
981
|
const handleOpenNowClick = (selected: boolean) => {
|
|
796
982
|
if (selected === isOpenNowSelected) {
|
|
@@ -809,6 +995,7 @@ const LocatorInternal = ({
|
|
|
809
995
|
});
|
|
810
996
|
setIsOpenNowSelected(selected);
|
|
811
997
|
searchActions.setOffset(0);
|
|
998
|
+
preserveMapView.current = false;
|
|
812
999
|
executeSearch(searchActions);
|
|
813
1000
|
};
|
|
814
1001
|
|
|
@@ -847,6 +1034,7 @@ const LocatorInternal = ({
|
|
|
847
1034
|
// Always reload from offset 0 if switching to mobile
|
|
848
1035
|
setMobileResults([]);
|
|
849
1036
|
searchActions.setOffset(0);
|
|
1037
|
+
preserveMapView.current = false;
|
|
850
1038
|
executeSearch(searchActions);
|
|
851
1039
|
setSearchState("loading");
|
|
852
1040
|
}, [currentOffset, isMobile, searchActions, searchLoading]);
|
|
@@ -867,7 +1055,7 @@ const LocatorInternal = ({
|
|
|
867
1055
|
|
|
868
1056
|
const handleDistanceClick = (
|
|
869
1057
|
distance: number,
|
|
870
|
-
distanceUnit:
|
|
1058
|
+
distanceUnit: DistanceUnit
|
|
871
1059
|
) => {
|
|
872
1060
|
const existingFilters = searchFilters.static || [];
|
|
873
1061
|
let updatedFilters: SelectableStaticFilter[];
|
|
@@ -875,10 +1063,10 @@ const LocatorInternal = ({
|
|
|
875
1063
|
if (selectedDistanceOption === distance) {
|
|
876
1064
|
setSelectedDistanceMeters(null);
|
|
877
1065
|
setSelectedDistanceOption(null);
|
|
878
|
-
//
|
|
1066
|
+
// Restore the current location's base radius when deselecting a distance.
|
|
879
1067
|
updatedFilters = updateRadiusInNearFiltersOnLocationField(
|
|
880
1068
|
existingFilters,
|
|
881
|
-
|
|
1069
|
+
baseFilterRadius.current ?? defaultRadiusMeters
|
|
882
1070
|
);
|
|
883
1071
|
} else {
|
|
884
1072
|
setSelectedDistanceOption(distance);
|
|
@@ -889,15 +1077,21 @@ const LocatorInternal = ({
|
|
|
889
1077
|
}
|
|
890
1078
|
searchActions.setStaticFilters(updatedFilters);
|
|
891
1079
|
searchActions.setOffset(0);
|
|
1080
|
+
preserveMapView.current = false;
|
|
892
1081
|
executeSearch(searchActions);
|
|
893
1082
|
};
|
|
894
1083
|
|
|
1084
|
+
const handleDistanceUnitChange = (nextUnit: DistanceUnit) => {
|
|
1085
|
+
if (nextUnit === distanceUnit) return;
|
|
1086
|
+
setDistanceUnitOverride(nextUnit);
|
|
1087
|
+
};
|
|
1088
|
+
|
|
895
1089
|
const handleClearFiltersClick = () => {
|
|
896
1090
|
const existingFilters = searchFilters.static || [];
|
|
897
|
-
//
|
|
1091
|
+
// Restore the current location's base radius.
|
|
898
1092
|
const partiallyUpdatedFilters = updateRadiusInNearFiltersOnLocationField(
|
|
899
1093
|
existingFilters,
|
|
900
|
-
|
|
1094
|
+
baseFilterRadius.current ?? defaultRadiusMeters
|
|
901
1095
|
);
|
|
902
1096
|
const updatedFilters = deselectOpenNowFilters(partiallyUpdatedFilters);
|
|
903
1097
|
|
|
@@ -907,6 +1101,7 @@ const LocatorInternal = ({
|
|
|
907
1101
|
searchActions.resetFacets();
|
|
908
1102
|
// Execute search to update AppliedFilters components
|
|
909
1103
|
searchActions.setOffset(0);
|
|
1104
|
+
preserveMapView.current = false;
|
|
910
1105
|
executeSearch(searchActions);
|
|
911
1106
|
setSelectedDistanceMeters(null);
|
|
912
1107
|
setSelectedDistanceOption(null);
|
|
@@ -953,6 +1148,15 @@ const LocatorInternal = ({
|
|
|
953
1148
|
: false;
|
|
954
1149
|
// If no opt-in is required, the map is already enabled.
|
|
955
1150
|
const [mapEnabled, setMapEnabled] = React.useState(!requireMapOptIn);
|
|
1151
|
+
// Cancel pending searches when the prop or map is disabled, and on unmount.
|
|
1152
|
+
React.useEffect(
|
|
1153
|
+
() => cancelMapSearch,
|
|
1154
|
+
[autoSearchOnMapMove, mapEnabled, cancelMapSearch]
|
|
1155
|
+
);
|
|
1156
|
+
React.useEffect((): void => {
|
|
1157
|
+
cancelMapSearch();
|
|
1158
|
+
setShowSearchAreaButton(false);
|
|
1159
|
+
}, [urlNavigationVersion, cancelMapSearch]);
|
|
956
1160
|
// Adds unified [enable|disable]Map functions to the window.
|
|
957
1161
|
useEffect(() => {
|
|
958
1162
|
(window as any).enableMap = () => setMapEnabled(true);
|
|
@@ -1011,12 +1215,36 @@ const LocatorInternal = ({
|
|
|
1011
1215
|
showCurrentLocationButton={showCurrentLocationButton}
|
|
1012
1216
|
geolocationProps={{
|
|
1013
1217
|
handleClick: handleCurrentLocationClick,
|
|
1014
|
-
radius:
|
|
1015
|
-
preferredUnit === "mile"
|
|
1016
|
-
? DEFAULT_RADIUS
|
|
1017
|
-
: toMiles(DEFAULT_RADIUS), // this component uses miles, not meters
|
|
1218
|
+
radius: fromMeters(defaultRadiusMeters, "mile"),
|
|
1018
1219
|
}}
|
|
1019
1220
|
/>
|
|
1221
|
+
{showDistanceUnitToggle && (
|
|
1222
|
+
<div className="flex items-center justify-end gap-3 font-body-fontFamily text-body-sm-fontSize">
|
|
1223
|
+
<span>{t("distance", "Distance")}</span>
|
|
1224
|
+
<div
|
|
1225
|
+
role="group"
|
|
1226
|
+
aria-label={t("distance", "Distance")}
|
|
1227
|
+
className="inline-flex rounded-md border border-gray-300 overflow-hidden"
|
|
1228
|
+
>
|
|
1229
|
+
{DISTANCE_UNITS.map((unit) => (
|
|
1230
|
+
<button
|
|
1231
|
+
key={unit}
|
|
1232
|
+
type="button"
|
|
1233
|
+
aria-label={translateDistanceUnit(t, unit, 2)}
|
|
1234
|
+
aria-pressed={distanceUnit === unit}
|
|
1235
|
+
onClick={() => handleDistanceUnitChange(unit)}
|
|
1236
|
+
className={`px-3 py-1 font-bold ${
|
|
1237
|
+
distanceUnit === unit
|
|
1238
|
+
? "bg-palette-primary text-palette-primary-contrast"
|
|
1239
|
+
: "bg-white text-palette-primary-dark"
|
|
1240
|
+
}`}
|
|
1241
|
+
>
|
|
1242
|
+
{unit === MILE ? "mi" : "km"}
|
|
1243
|
+
</button>
|
|
1244
|
+
))}
|
|
1245
|
+
</div>
|
|
1246
|
+
</div>
|
|
1247
|
+
)}
|
|
1020
1248
|
</div>
|
|
1021
1249
|
<div className="relative flex-1 flex flex-col min-h-0">
|
|
1022
1250
|
<div className="px-8 py-4 text-body-fontSize border-y border-gray-300 inline-block">
|
|
@@ -1025,6 +1253,7 @@ const LocatorInternal = ({
|
|
|
1025
1253
|
searchState={searchState}
|
|
1026
1254
|
resultCount={resultCount}
|
|
1027
1255
|
selectedDistanceOption={selectedDistanceOption}
|
|
1256
|
+
distanceUnit={distanceUnit}
|
|
1028
1257
|
filterDisplayName={filterDisplayName}
|
|
1029
1258
|
/>
|
|
1030
1259
|
{hasFilterModalToggle && (
|
|
@@ -1071,6 +1300,7 @@ const LocatorInternal = ({
|
|
|
1071
1300
|
}
|
|
1072
1301
|
|
|
1073
1302
|
searchActions.setOffset(mobileResults.length);
|
|
1303
|
+
preserveMapView.current = false;
|
|
1074
1304
|
executeSearch(searchActions);
|
|
1075
1305
|
setSearchState("loading");
|
|
1076
1306
|
}}
|
|
@@ -1100,6 +1330,7 @@ const LocatorInternal = ({
|
|
|
1100
1330
|
handleOpenNowClick={handleOpenNowClick}
|
|
1101
1331
|
showDistanceOptions={showDistanceOptions}
|
|
1102
1332
|
selectedDistanceOption={selectedDistanceOption}
|
|
1333
|
+
distanceUnit={distanceUnit}
|
|
1103
1334
|
handleDistanceClick={handleDistanceClick}
|
|
1104
1335
|
handleCloseModalClick={() => setShowFilterModal(false)}
|
|
1105
1336
|
handleClearFiltersClick={handleClearFiltersClick}
|
|
@@ -1141,10 +1372,10 @@ const LocatorInternal = ({
|
|
|
1141
1372
|
</div>
|
|
1142
1373
|
</div>
|
|
1143
1374
|
)}
|
|
1144
|
-
{showSearchAreaButton && (
|
|
1375
|
+
{showSearchAreaButton && !autoSearchOnMapMove && (
|
|
1145
1376
|
<div className="absolute top-10 left-0 right-0 flex justify-center">
|
|
1146
1377
|
<Button
|
|
1147
|
-
onClick={handleSearchAreaClick}
|
|
1378
|
+
onClick={() => handleSearchAreaClick()}
|
|
1148
1379
|
className="py-2 px-4 shadow-xl"
|
|
1149
1380
|
>
|
|
1150
1381
|
<Body>{t("searchThisArea", "Search This Area")}</Body>
|