@yext/visual-editor 1.4.14 → 2.0.0-beta.10
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-DN65KSX7.js +119824 -0
- package/dist/SectionLibraryVisualEditorProvider.css +1 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/Address.tsx +251 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/HeadingText.tsx +147 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/HoursStatus.tsx +157 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/HoursTable.tsx +164 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/MapboxStaticMap.tsx +205 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/Phone.tsx +155 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/image/EmptyImageState.tsx +168 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/image/Image.tsx +275 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/image/styling.ts +66 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/index.ts +13 -0
- package/dist/cli/assets/directory-locator-source/components/sections/Breadcrumbs.tsx +298 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/Directory.test.tsx +872 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/Directory.tsx +298 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/DirectoryCard.tsx +507 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/DirectoryWrapper.tsx +499 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/directoryChildReference.test.tsx +226 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/directoryChildReference.tsx +98 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Filters.test.tsx +147 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Filters.tsx +691 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Locator.test.tsx +1551 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Locator.tsx +541 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorFields.test.ts +43 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorResultCard.tsx +1594 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorWrapper.tsx +1157 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Map.tsx +304 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/MapPinIcon.tsx +160 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Results.tsx +267 -0
- package/dist/cli/assets/directory-locator-source/sectionLibrarySupport.ts +277 -0
- package/dist/cli/yextve.js +16992 -0
- package/dist/createYextFieldTransforms-CrIkiJ_X.d.ts +2157 -0
- package/dist/index.d.ts +534 -6352
- package/dist/locales/page/cs/visual-editor.json +85 -0
- package/dist/locales/page/da/visual-editor.json +73 -0
- package/dist/locales/page/de/visual-editor.json +73 -0
- package/dist/locales/page/en/visual-editor.json +73 -0
- package/dist/locales/page/en-GB/visual-editor.json +73 -0
- package/dist/locales/page/es/visual-editor.json +79 -0
- package/dist/locales/page/et/visual-editor.json +73 -0
- package/dist/locales/page/fi/visual-editor.json +73 -0
- package/dist/locales/page/fr/visual-editor.json +79 -0
- package/dist/locales/page/hr/visual-editor.json +79 -0
- package/dist/locales/page/hu/visual-editor.json +73 -0
- package/dist/locales/page/it/visual-editor.json +79 -0
- package/dist/locales/page/ja/visual-editor.json +73 -0
- package/dist/locales/page/lt/visual-editor.json +85 -0
- package/dist/locales/page/lv/visual-editor.json +77 -0
- package/dist/locales/page/nb/visual-editor.json +73 -0
- package/dist/locales/page/nl/visual-editor.json +73 -0
- package/dist/locales/page/pl/visual-editor.json +85 -0
- package/dist/locales/page/pt/visual-editor.json +79 -0
- package/dist/locales/page/ro/visual-editor.json +79 -0
- package/dist/locales/page/sk/visual-editor.json +85 -0
- package/dist/locales/page/sv/visual-editor.json +73 -0
- package/dist/locales/page/tr/visual-editor.json +73 -0
- package/dist/locales/page/zh/visual-editor.json +73 -0
- package/dist/locales/page/zh-TW/visual-editor.json +73 -0
- package/dist/locales/platform/cs/visual-editor.json +651 -0
- package/dist/locales/platform/da/visual-editor.json +625 -0
- package/dist/locales/platform/de/visual-editor.json +625 -0
- package/dist/locales/platform/en/visual-editor.json +625 -0
- package/dist/locales/platform/en-GB/visual-editor.json +625 -0
- package/dist/locales/platform/es/visual-editor.json +638 -0
- package/dist/locales/platform/et/visual-editor.json +625 -0
- package/dist/locales/platform/fi/visual-editor.json +625 -0
- package/dist/locales/platform/fr/visual-editor.json +638 -0
- package/dist/locales/platform/hr/visual-editor.json +638 -0
- package/dist/locales/platform/hu/visual-editor.json +625 -0
- package/dist/locales/platform/it/visual-editor.json +638 -0
- package/dist/locales/platform/ja/visual-editor.json +625 -0
- package/dist/locales/platform/lt/visual-editor.json +651 -0
- package/dist/locales/platform/lv/visual-editor.json +633 -0
- package/dist/locales/platform/nb/visual-editor.json +625 -0
- package/dist/locales/platform/nl/visual-editor.json +625 -0
- package/dist/locales/platform/pl/visual-editor.json +651 -0
- package/dist/locales/platform/pt/visual-editor.json +638 -0
- package/dist/locales/platform/ro/visual-editor.json +638 -0
- package/dist/locales/platform/sk/visual-editor.json +651 -0
- package/dist/locales/platform/sv/visual-editor.json +625 -0
- package/dist/locales/platform/tr/visual-editor.json +625 -0
- package/dist/locales/platform/zh/visual-editor.json +625 -0
- package/dist/locales/platform/zh-TW/visual-editor.json +625 -0
- package/dist/plugin/internal/layoutGeneration/limits.d.ts +28 -0
- package/dist/plugin/internal/sectionLibraryValidation/builtInTranslationResources.d.ts +3 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/api/api.d.ts +7 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/api/libraryMetadata.d.ts +7 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/code/importRules.d.ts +13 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/code/validateCode.d.ts +10 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/code/xssRules.d.ts +7 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/structure/structure.d.ts +7 -0
- package/dist/plugin/internal/sectionLibraryValidation/types.d.ts +48 -0
- package/dist/plugin/internal/sectionLibraryValidation/validateSectionLibrary.d.ts +8 -0
- package/dist/plugin/internal/sectionLibraryValidation/validationError.d.ts +6 -0
- package/dist/plugin/plugin.js +7013 -5873
- package/dist/plugin/types/entityFields.d.ts +21 -0
- package/dist/plugin/types/generationPrompts.d.ts +19 -0
- package/dist/plugin/types/generationSettings.d.ts +12 -0
- package/dist/plugin/types/images.d.ts +62 -0
- package/dist/plugin/types/sectionLibrary.d.ts +101 -0
- package/dist/plugin/types/types.d.ts +204 -0
- package/dist/plugin/types/videos.d.ts +24 -0
- package/dist/plugin/utils/i18n/locales.d.ts +5 -0
- package/dist/plugin/utils/i18n/translationResources.d.ts +41 -0
- package/dist/plugin/utils/normalizeLocale.d.ts +8 -0
- package/dist/plugin/utils/plainText.d.ts +6 -0
- package/dist/plugin/vite-plugin/index.d.ts +2 -0
- package/dist/plugin/vite-plugin/layout-generation/generationLogger.d.ts +5 -0
- package/dist/plugin/vite-plugin/layout-generation/generationReports.d.ts +13 -0
- package/dist/plugin/vite-plugin/layout-generation/middleware.d.ts +14 -0
- package/dist/plugin/vite-plugin/layout-generation/modelProxy.d.ts +9 -0
- package/dist/plugin/vite-plugin/layout-generation/prompts.d.ts +17 -0
- package/dist/plugin/vite-plugin/layout-generation/settings.d.ts +3 -0
- package/dist/plugin/vite-plugin/local-editor/artifacts.d.ts +20 -0
- package/dist/plugin/vite-plugin/local-editor/config.d.ts +11 -0
- package/dist/plugin/vite-plugin/local-editor/data.d.ts +12 -0
- package/dist/plugin/vite-plugin/local-editor/entityFields.d.ts +13 -0
- package/dist/plugin/vite-plugin/local-editor/fixtureData.d.ts +12 -0
- package/dist/plugin/vite-plugin/local-editor/generatedFiles.d.ts +33 -0
- package/dist/plugin/vite-plugin/local-editor/server.d.ts +34 -0
- package/dist/plugin/vite-plugin/local-editor/types.d.ts +125 -0
- package/dist/plugin/vite-plugin/local-editor/utils.d.ts +16 -0
- package/dist/plugin/vite-plugin/plugin.d.ts +8 -0
- package/dist/plugin/vite-plugin/section-library/migrationRegistry.d.ts +6 -0
- package/dist/plugin/vite-plugin/section-library/sectionFrontmatter.d.ts +3 -0
- package/dist/plugin/vite-plugin/section-library/sectionLibraryGenerator.d.ts +21 -0
- package/dist/plugin/vite-plugin/section-library/sharedComponentRegistry.d.ts +16 -0
- package/dist/section-library-support.js +178 -0
- package/dist/sectionLibrarySupport.d.ts +703 -0
- package/dist/style.css +1 -1
- package/dist/visual-editor-6mKs9VUe.js +842 -0
- package/dist/visual-editor-BK6fTU7k.js +804 -0
- package/dist/visual-editor-BXYlpe7B.js +145 -0
- package/dist/visual-editor-BruRrJYN.js +804 -0
- package/dist/visual-editor-Bs3wAslG.js +804 -0
- package/dist/visual-editor-Bxy81Ezy.js +145 -0
- package/dist/visual-editor-C0vq2BRM.js +145 -0
- package/dist/visual-editor-C9TLeAzP.js +804 -0
- package/dist/visual-editor-CCgmYV5S.js +169 -0
- package/dist/visual-editor-CERViyTJ.js +145 -0
- package/dist/visual-editor-CHWtMtlu.js +823 -0
- package/dist/visual-editor-CcfUKpnd.js +804 -0
- package/dist/visual-editor-CjORnP1D.js +169 -0
- package/dist/visual-editor-ClC6hoz3.js +804 -0
- package/dist/visual-editor-CmomGJB8.js +157 -0
- package/dist/visual-editor-CtQwadxQ.js +842 -0
- package/dist/visual-editor-Cymg8ID2.js +169 -0
- package/dist/visual-editor-D2Hk1nhM.js +145 -0
- package/dist/visual-editor-D7VeTRK_.js +816 -0
- package/dist/visual-editor-D8MRFn5x.js +157 -0
- package/dist/visual-editor-DOXtCqRv.js +145 -0
- package/dist/visual-editor-DQEd3xwY.js +145 -0
- package/dist/visual-editor-DTE5kxrA.js +804 -0
- package/dist/visual-editor-DUngIOnE.js +157 -0
- package/dist/visual-editor-DeZVZYfd.js +169 -0
- package/dist/visual-editor-DfJMZpiP.js +145 -0
- package/dist/visual-editor-DgAsQK9D.js +145 -0
- package/dist/visual-editor-Dhi__-7_.js +145 -0
- package/dist/visual-editor-DjTEbi-1.js +842 -0
- package/dist/visual-editor-DjdqpJU-.js +145 -0
- package/dist/visual-editor-DkHhrFsX.js +804 -0
- package/dist/visual-editor-DtL-Zuv_.js +804 -0
- package/dist/visual-editor-Duishbsa.js +842 -0
- package/dist/visual-editor-DvuH3jyL.js +157 -0
- package/dist/visual-editor-LXMNWXry.js +823 -0
- package/dist/visual-editor-QpGupjY5.js +823 -0
- package/dist/visual-editor-TfVDfO5_.js +145 -0
- package/dist/visual-editor-W_ZDmMFn.js +145 -0
- package/dist/visual-editor-_TatCCAS.js +804 -0
- package/dist/visual-editor-b7ALusk8.js +145 -0
- package/dist/visual-editor-erGXf3kS.js +157 -0
- package/dist/visual-editor-gEaWoNRu.js +804 -0
- package/dist/visual-editor-gjpr-NAN.js +804 -0
- package/dist/visual-editor-qJW0uCiQ.js +804 -0
- package/dist/visual-editor-sOPDMkOR.js +823 -0
- package/dist/visual-editor-tPb7n5l8.js +823 -0
- package/dist/visual-editor-vomNdlNO.js +804 -0
- package/dist/visual-editor-xnDHZFuO.js +153 -0
- package/dist/visual-editor-yiWZqIH0.js +157 -0
- package/dist/visual-editor-zKhC7_0C.js +823 -0
- package/dist/visual-editor.css +1 -0
- package/dist/visual-editor.js +18578 -137536
- package/package.json +50 -26
- package/dist/editor.css +0 -1
- package/dist/visual-editor-6pnSx-yp.js +0 -223
- package/dist/visual-editor-9ZW3nq5u.js +0 -247
- package/dist/visual-editor-B1RXDqNi.js +0 -1063
- package/dist/visual-editor-BAahiZ1l.js +0 -223
- package/dist/visual-editor-BC2LjdoF.js +0 -223
- package/dist/visual-editor-BPnfBfk1.js +0 -1051
- package/dist/visual-editor-BQiE5eVW.js +0 -1051
- package/dist/visual-editor-BTv-6Pnk.js +0 -1051
- package/dist/visual-editor-BUWp03gX.js +0 -235
- package/dist/visual-editor-Bb3c6iGV.js +0 -223
- package/dist/visual-editor-BipczqTj.js +0 -1075
- package/dist/visual-editor-BlIUd_n_.js +0 -1051
- package/dist/visual-editor-BoPLXEu2.js +0 -223
- package/dist/visual-editor-Bzmpi_9a.js +0 -1063
- package/dist/visual-editor-C38IiBTR.js +0 -235
- package/dist/visual-editor-C9tacnim.js +0 -247
- package/dist/visual-editor-CVa3iu5h.js +0 -1051
- package/dist/visual-editor-CXTL8Ik0.js +0 -1051
- package/dist/visual-editor-CYeahjFX.js +0 -231
- package/dist/visual-editor-CZ2SM6Jc.js +0 -1063
- package/dist/visual-editor-CZDmQI-A.js +0 -1063
- package/dist/visual-editor-C_cHJ6BN.js +0 -1051
- package/dist/visual-editor-Cf3nFbw3.js +0 -235
- package/dist/visual-editor-CiR0metz.js +0 -1051
- package/dist/visual-editor-CoX_NnS-.js +0 -223
- package/dist/visual-editor-Cu8II23Y.js +0 -223
- package/dist/visual-editor-CvXFxocc.js +0 -1063
- package/dist/visual-editor-Cxu6nkib.js +0 -1051
- package/dist/visual-editor-D-3VVfjR.js +0 -223
- package/dist/visual-editor-D-ktbg7q.js +0 -223
- package/dist/visual-editor-D9G5eAAU.js +0 -1051
- package/dist/visual-editor-D9MrqEya.js +0 -223
- package/dist/visual-editor-DAKXBbjV.js +0 -1075
- package/dist/visual-editor-DBmJk7ZR.js +0 -235
- package/dist/visual-editor-DG-c2LU9.js +0 -1051
- package/dist/visual-editor-DI_Vk989.js +0 -1051
- package/dist/visual-editor-DOOYgnjP.js +0 -235
- package/dist/visual-editor-DRx3Ax_O.js +0 -1075
- package/dist/visual-editor-DZ66sria.js +0 -1051
- package/dist/visual-editor-DZTPhYcr.js +0 -247
- package/dist/visual-editor-DcH7WJVI.js +0 -223
- package/dist/visual-editor-DdYXgEbR.js +0 -1059
- package/dist/visual-editor-DeWzgcue.js +0 -1063
- package/dist/visual-editor-Dm5ZNn8C.js +0 -223
- package/dist/visual-editor-DqLCIWPQ.js +0 -1051
- package/dist/visual-editor-NoU28r5Y.js +0 -223
- package/dist/visual-editor-WjrJ9nPc.js +0 -235
- package/dist/visual-editor-_h-sdbID.js +0 -223
- package/dist/visual-editor-r4gSQqFM.js +0 -1075
- package/dist/visual-editor-ujQ29mao.js +0 -247
package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorWrapper.tsx
ADDED
|
@@ -0,0 +1,1157 @@
|
|
|
1
|
+
import { WithPuckProps } from "@puckeditor/core";
|
|
2
|
+
import {
|
|
3
|
+
FilterSearchResponse,
|
|
4
|
+
Matcher,
|
|
5
|
+
NearFilterValue,
|
|
6
|
+
provideHeadless,
|
|
7
|
+
Result,
|
|
8
|
+
SearchHeadlessProvider,
|
|
9
|
+
SelectableStaticFilter,
|
|
10
|
+
useSearchActions,
|
|
11
|
+
useSearchState,
|
|
12
|
+
} from "@yext/search-headless-react";
|
|
13
|
+
import { useAnalytics } from "@yext/pages-components";
|
|
14
|
+
import {
|
|
15
|
+
AnalyticsProvider,
|
|
16
|
+
AppliedFilters,
|
|
17
|
+
CardProps,
|
|
18
|
+
Coordinate,
|
|
19
|
+
executeSearch,
|
|
20
|
+
FilterSearch,
|
|
21
|
+
getUserLocation,
|
|
22
|
+
MapMarkerOptions,
|
|
23
|
+
OnDragHandler,
|
|
24
|
+
OnSelectParams,
|
|
25
|
+
Pagination,
|
|
26
|
+
SearchI18nextProvider,
|
|
27
|
+
useAnalytics as useSearchAnalytics,
|
|
28
|
+
VerticalResults,
|
|
29
|
+
} from "@yext/search-ui-react";
|
|
30
|
+
import React, { useEffect } from "react";
|
|
31
|
+
import { useTranslation } from "react-i18next";
|
|
32
|
+
import { FaSlidersH } from "react-icons/fa";
|
|
33
|
+
import { useDocument } from "../../../hooks/useDocument.tsx";
|
|
34
|
+
import { usePreviewWindow } from "../../../hooks/usePreviewWindow.ts";
|
|
35
|
+
import { getViewport, useWindowWidth } from "../../../hooks/useViewport.ts";
|
|
36
|
+
import { resolveLocalizedAssetImage } from "../../../types/images.ts";
|
|
37
|
+
import {
|
|
38
|
+
getPreferredDistanceUnit,
|
|
39
|
+
toMeters,
|
|
40
|
+
toMiles,
|
|
41
|
+
} from "../../../utils/i18n/distance.ts";
|
|
42
|
+
import { resolveComponentData } from "../../../utils/resolveComponentData.tsx";
|
|
43
|
+
import {
|
|
44
|
+
createSearchAnalyticsConfig,
|
|
45
|
+
createSearchHeadlessConfig,
|
|
46
|
+
} from "../../../utils/searchHeadlessConfig.ts";
|
|
47
|
+
import { getThemeColorCssValue } from "../../../utils/colors.ts";
|
|
48
|
+
import { Button } from "../../atoms/button.tsx";
|
|
49
|
+
import { Body } from "../../atoms/body.tsx";
|
|
50
|
+
import { Heading } from "../../atoms/heading.tsx";
|
|
51
|
+
import {
|
|
52
|
+
DEFAULT_ENTITY_TYPE,
|
|
53
|
+
LocatorEntityType,
|
|
54
|
+
getLocatorEntityTypeSourceMap,
|
|
55
|
+
isLocatorEntityType,
|
|
56
|
+
} from "../../../utils/locatorEntityTypes.ts";
|
|
57
|
+
import {
|
|
58
|
+
DEFAULT_LOCATOR_RESULT_CARD_PROPS,
|
|
59
|
+
Location,
|
|
60
|
+
LocatorResultCard,
|
|
61
|
+
} from "./LocatorResultCard.tsx";
|
|
62
|
+
import type { LocatorProps } from "./Locator.tsx";
|
|
63
|
+
import {
|
|
64
|
+
COUNTRY_CODE_FIELD,
|
|
65
|
+
FilterModal,
|
|
66
|
+
LOCATION_FIELD,
|
|
67
|
+
buildEqualsLocationFilter,
|
|
68
|
+
buildNearLocationFilterFromCoords,
|
|
69
|
+
buildNearLocationFilterFromPrevious,
|
|
70
|
+
deselectOpenNowFilters,
|
|
71
|
+
HOURS_FIELD,
|
|
72
|
+
updateRadiusInNearFiltersOnLocationField,
|
|
73
|
+
} from "./Filters.tsx";
|
|
74
|
+
import {
|
|
75
|
+
areValidCoordinates,
|
|
76
|
+
DEFAULT_RADIUS,
|
|
77
|
+
getConfiguredMapCenterOrDefault,
|
|
78
|
+
LocatorMap,
|
|
79
|
+
LoadingMapPlaceholder,
|
|
80
|
+
LocationStyleConfig,
|
|
81
|
+
makiIconMap,
|
|
82
|
+
} from "./Map.tsx";
|
|
83
|
+
import {
|
|
84
|
+
MobileLocatorResultsSection,
|
|
85
|
+
ResultsCountSummary,
|
|
86
|
+
RESULTS_LIMIT,
|
|
87
|
+
SearchState,
|
|
88
|
+
} from "./Results.tsx";
|
|
89
|
+
|
|
90
|
+
export const INITIAL_LOCATION_KEY = "initialLocation";
|
|
91
|
+
const LOCATION_QUERY_KEY = "q";
|
|
92
|
+
|
|
93
|
+
const formatCoordinateQuery = (lat: number, lng: number, radius: number) =>
|
|
94
|
+
`${lat},${lng},${radius}`;
|
|
95
|
+
|
|
96
|
+
const parseCoordinateQuery = (query: string) => {
|
|
97
|
+
const parts = query.split(",");
|
|
98
|
+
if (parts.length !== 3 || parts.some((part) => part.trim() === "")) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const [lat, lng, radius] = parts.map(Number);
|
|
102
|
+
if (
|
|
103
|
+
!Number.isFinite(lat) ||
|
|
104
|
+
!Number.isFinite(lng) ||
|
|
105
|
+
!Number.isFinite(radius) ||
|
|
106
|
+
!areValidCoordinates(lat, lng) ||
|
|
107
|
+
radius <= 0
|
|
108
|
+
) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
return { lat, lng, radius };
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const updateLocationQuery = (location: string) => {
|
|
115
|
+
const nextUrl = new URL(window.location.href);
|
|
116
|
+
nextUrl.searchParams.set(LOCATION_QUERY_KEY, location);
|
|
117
|
+
nextUrl.searchParams.delete(INITIAL_LOCATION_KEY);
|
|
118
|
+
if (nextUrl.href !== window.location.href) {
|
|
119
|
+
window.history.pushState(window.history.state, "", nextUrl);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export const LocatorWrapper = (props: WithPuckProps<LocatorProps>) => {
|
|
124
|
+
const streamDocument = useDocument();
|
|
125
|
+
const { searchAnalyticsConfig, searcher } = React.useMemo(() => {
|
|
126
|
+
const searchHeadlessConfig = createSearchHeadlessConfig(
|
|
127
|
+
streamDocument,
|
|
128
|
+
props.puck.metadata?.experienceKeyEnvVar
|
|
129
|
+
);
|
|
130
|
+
if (searchHeadlessConfig === undefined) {
|
|
131
|
+
return { searchAnalyticsConfig: undefined, searcher: undefined };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const searchAnalyticsConfig = createSearchAnalyticsConfig(streamDocument);
|
|
135
|
+
return {
|
|
136
|
+
searchAnalyticsConfig,
|
|
137
|
+
searcher: provideHeadless(searchHeadlessConfig),
|
|
138
|
+
};
|
|
139
|
+
}, [streamDocument.id, streamDocument.locale]);
|
|
140
|
+
|
|
141
|
+
if (searcher === undefined || searchAnalyticsConfig === undefined) {
|
|
142
|
+
console.warn(
|
|
143
|
+
"Could not create Locator component because Search Headless or Search Analytics config is undefined. Please check your environment variables."
|
|
144
|
+
);
|
|
145
|
+
return <></>;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
searcher.setSessionTrackingEnabled(true);
|
|
149
|
+
return (
|
|
150
|
+
<SearchHeadlessProvider searcher={searcher}>
|
|
151
|
+
<SearchI18nextProvider searcher={searcher}>
|
|
152
|
+
<AnalyticsProvider {...searchAnalyticsConfig}>
|
|
153
|
+
<LocatorInternal {...props} />
|
|
154
|
+
</AnalyticsProvider>
|
|
155
|
+
</SearchI18nextProvider>
|
|
156
|
+
</SearchHeadlessProvider>
|
|
157
|
+
);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const LocatorInternal = ({
|
|
161
|
+
mapStyle,
|
|
162
|
+
locationStyles,
|
|
163
|
+
filters: {
|
|
164
|
+
openNowButton,
|
|
165
|
+
showDistanceOptions,
|
|
166
|
+
accentColor,
|
|
167
|
+
facetFields,
|
|
168
|
+
keywordsDisplayName,
|
|
169
|
+
},
|
|
170
|
+
mapStartingLocation,
|
|
171
|
+
resultCard: resultCardConfigs,
|
|
172
|
+
distanceDisplay,
|
|
173
|
+
pageHeading,
|
|
174
|
+
}: LocatorProps) => {
|
|
175
|
+
// Adds unified [enable|disable]YextAnalytics to the window for both Pages and Search
|
|
176
|
+
// analytics. Typically used during consent banner implementation.
|
|
177
|
+
const searchAnalytics = useSearchAnalytics();
|
|
178
|
+
const pagesAnalytics = useAnalytics();
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
(window as any).enableYextAnalytics = () => {
|
|
181
|
+
searchAnalytics?.optIn();
|
|
182
|
+
pagesAnalytics?.optIn();
|
|
183
|
+
};
|
|
184
|
+
(window as any).disableYextAnalytics = () => {
|
|
185
|
+
searchAnalytics?.optOut();
|
|
186
|
+
pagesAnalytics?.optOut();
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
return () => {
|
|
190
|
+
delete (window as any).enableYextAnalytics;
|
|
191
|
+
delete (window as any).disableYextAnalytics;
|
|
192
|
+
};
|
|
193
|
+
}, [searchAnalytics, pagesAnalytics]);
|
|
194
|
+
|
|
195
|
+
const { t, i18n } = useTranslation();
|
|
196
|
+
const previewWindow = usePreviewWindow();
|
|
197
|
+
const windowWidth = useWindowWidth(previewWindow);
|
|
198
|
+
const { isMobile } = getViewport(windowWidth);
|
|
199
|
+
const preferredUnit = getPreferredDistanceUnit(i18n.language);
|
|
200
|
+
const streamDocument = useDocument();
|
|
201
|
+
const entityTypeSourceMap = getLocatorEntityTypeSourceMap(streamDocument);
|
|
202
|
+
const entityTypes =
|
|
203
|
+
Object.keys(entityTypeSourceMap).filter(isLocatorEntityType);
|
|
204
|
+
const resultCount = useSearchState(
|
|
205
|
+
(state) => state.vertical.resultsCount || 0
|
|
206
|
+
);
|
|
207
|
+
const searchResults = useSearchState(
|
|
208
|
+
(state) => (state.vertical.results || []) as Result<Location>[]
|
|
209
|
+
);
|
|
210
|
+
// Manage browser forward/back button for location searches
|
|
211
|
+
const [urlNavigationVersion, setUrlNavigationVersion] = React.useState(0);
|
|
212
|
+
const [showCurrentLocationButton, setShowCurrentLocationButton] =
|
|
213
|
+
React.useState(false);
|
|
214
|
+
React.useEffect(() => {
|
|
215
|
+
const handlePopState = () =>
|
|
216
|
+
setUrlNavigationVersion((version) => version + 1);
|
|
217
|
+
const controller = new AbortController();
|
|
218
|
+
window.addEventListener("popstate", handlePopState, {
|
|
219
|
+
signal: controller.signal,
|
|
220
|
+
});
|
|
221
|
+
return () => controller.abort();
|
|
222
|
+
}, []);
|
|
223
|
+
React.useEffect(() => {
|
|
224
|
+
if (new URLSearchParams(window.location.search).has(LOCATION_QUERY_KEY)) {
|
|
225
|
+
setShowCurrentLocationButton(true);
|
|
226
|
+
}
|
|
227
|
+
}, [urlNavigationVersion]);
|
|
228
|
+
|
|
229
|
+
const iframe =
|
|
230
|
+
typeof document === "undefined"
|
|
231
|
+
? undefined
|
|
232
|
+
: (document.getElementById("preview-frame") as HTMLIFrameElement);
|
|
233
|
+
|
|
234
|
+
let mapboxApiKey = streamDocument._env?.YEXT_MAPBOX_API_KEY;
|
|
235
|
+
if (
|
|
236
|
+
iframe?.contentDocument &&
|
|
237
|
+
streamDocument._env?.YEXT_EDIT_LAYOUT_MODE_MAPBOX_API_KEY
|
|
238
|
+
) {
|
|
239
|
+
// If we are in the layout editor, use the non-URL-restricted Mapbox API key
|
|
240
|
+
mapboxApiKey = streamDocument._env.YEXT_EDIT_LAYOUT_MODE_MAPBOX_API_KEY;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const [showSearchAreaButton, setShowSearchAreaButton] = React.useState(false);
|
|
244
|
+
const [mapCenter, setMapCenter] = React.useState<Coordinate | undefined>();
|
|
245
|
+
const [mapRadius, setMapRadius] = React.useState<number | undefined>();
|
|
246
|
+
/** Explicit filter radius selected by the user, in meters */
|
|
247
|
+
const [selectedDistanceMeters, setSelectedDistanceMeters] = React.useState<
|
|
248
|
+
number | null
|
|
249
|
+
>(null);
|
|
250
|
+
const [selectedDistanceOption, setSelectedDistanceOption] = React.useState<
|
|
251
|
+
number | null
|
|
252
|
+
>(null);
|
|
253
|
+
/** Radius of the current location filter before a distance option is applied */
|
|
254
|
+
const apiFilterRadius = React.useRef<number | null>(null);
|
|
255
|
+
|
|
256
|
+
const handleDrag: OnDragHandler = (center, bounds) => {
|
|
257
|
+
setMapCenter({
|
|
258
|
+
latitude: center.latitude,
|
|
259
|
+
longitude: center.longitude,
|
|
260
|
+
});
|
|
261
|
+
setMapRadius(center.distanceTo(bounds.getNorthEast()));
|
|
262
|
+
setShowSearchAreaButton(true);
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const [isOpenNowSelected, setIsOpenNowSelected] = React.useState(false);
|
|
266
|
+
const openNowFilter: SelectableStaticFilter = React.useMemo(
|
|
267
|
+
() => ({
|
|
268
|
+
filter: {
|
|
269
|
+
kind: "fieldValue",
|
|
270
|
+
fieldId: HOURS_FIELD,
|
|
271
|
+
matcher: Matcher.OpenAt,
|
|
272
|
+
value: "now",
|
|
273
|
+
},
|
|
274
|
+
selected: isOpenNowSelected,
|
|
275
|
+
displayName: t("openNow", "Open Now"),
|
|
276
|
+
}),
|
|
277
|
+
[isOpenNowSelected]
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
const searchActions = useSearchActions();
|
|
281
|
+
const searchFilters = useSearchState((state) => state.filters);
|
|
282
|
+
|
|
283
|
+
const handleSearchAreaClick = () => {
|
|
284
|
+
if (mapCenter && mapRadius) {
|
|
285
|
+
searchActions.setOffset(0);
|
|
286
|
+
const locationFilter: SelectableStaticFilter = {
|
|
287
|
+
selected: true,
|
|
288
|
+
displayName: "",
|
|
289
|
+
filter: {
|
|
290
|
+
kind: "fieldValue",
|
|
291
|
+
fieldId: LOCATION_FIELD,
|
|
292
|
+
value: {
|
|
293
|
+
lat: mapCenter.latitude,
|
|
294
|
+
lng: mapCenter.longitude,
|
|
295
|
+
radius: mapRadius,
|
|
296
|
+
name: t("customSearchArea", "Custom Search Area"),
|
|
297
|
+
},
|
|
298
|
+
matcher: Matcher.Near,
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
apiFilterRadius.current = mapRadius;
|
|
302
|
+
searchActions.setStaticFilters([locationFilter, openNowFilter]);
|
|
303
|
+
searchActions.executeVerticalQuery();
|
|
304
|
+
setSearchState("loading");
|
|
305
|
+
setShowSearchAreaButton(false);
|
|
306
|
+
updateLocationQuery(
|
|
307
|
+
formatCoordinateQuery(
|
|
308
|
+
mapCenter.latitude,
|
|
309
|
+
mapCenter.longitude,
|
|
310
|
+
mapRadius
|
|
311
|
+
)
|
|
312
|
+
);
|
|
313
|
+
setShowCurrentLocationButton(true);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
const handleCurrentLocationClick = (position: GeolocationPosition) => {
|
|
318
|
+
const { latitude, longitude, accuracy } = position.coords;
|
|
319
|
+
const radius = Math.max(accuracy, toMeters(DEFAULT_RADIUS, preferredUnit));
|
|
320
|
+
const locationFilter = buildNearLocationFilterFromCoords(
|
|
321
|
+
latitude,
|
|
322
|
+
longitude,
|
|
323
|
+
radius,
|
|
324
|
+
t("currentLocation", "Current Location")
|
|
325
|
+
);
|
|
326
|
+
apiFilterRadius.current = radius;
|
|
327
|
+
const nonLocationFilters = (searchFilters.static || []).filter(
|
|
328
|
+
(staticFilter) =>
|
|
329
|
+
staticFilter.filter.kind !== "fieldValue" ||
|
|
330
|
+
![LOCATION_FIELD, "builtin.region", COUNTRY_CODE_FIELD].includes(
|
|
331
|
+
staticFilter.filter.fieldId
|
|
332
|
+
)
|
|
333
|
+
);
|
|
334
|
+
searchActions.setOffset(0);
|
|
335
|
+
searchActions.setStaticFilters([...nonLocationFilters, locationFilter]);
|
|
336
|
+
searchActions.executeVerticalQuery();
|
|
337
|
+
setSearchState("loading");
|
|
338
|
+
updateLocationQuery(formatCoordinateQuery(latitude, longitude, radius));
|
|
339
|
+
setShowCurrentLocationButton(true);
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const selectedFacets: string[] = React.useMemo(
|
|
343
|
+
() =>
|
|
344
|
+
facetFields?.selections
|
|
345
|
+
?.filter((selection) => selection.value !== undefined)
|
|
346
|
+
?.map((selection) => selection.value as string) ?? [],
|
|
347
|
+
[facetFields]
|
|
348
|
+
);
|
|
349
|
+
React.useEffect(() => {
|
|
350
|
+
searchActions.setFacetAllowList(selectedFacets);
|
|
351
|
+
}, [searchActions, selectedFacets]);
|
|
352
|
+
|
|
353
|
+
const filterDisplayName = useSearchState(
|
|
354
|
+
(state) =>
|
|
355
|
+
state.filters?.static?.find(
|
|
356
|
+
(filter) =>
|
|
357
|
+
filter.filter.kind === "fieldValue" &&
|
|
358
|
+
(filter.filter.fieldId === LOCATION_FIELD ||
|
|
359
|
+
filter.filter.fieldId === COUNTRY_CODE_FIELD)
|
|
360
|
+
)?.displayName
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
const handleFilterSelect = (params: OnSelectParams) => {
|
|
364
|
+
const newDisplayName = params.newDisplayName;
|
|
365
|
+
const filter = params.newFilter;
|
|
366
|
+
|
|
367
|
+
let locationFilter: SelectableStaticFilter;
|
|
368
|
+
let nearFilterValue: NearFilterValue | undefined;
|
|
369
|
+
switch (filter.matcher) {
|
|
370
|
+
case Matcher.Near: {
|
|
371
|
+
nearFilterValue = filter.value as NearFilterValue;
|
|
372
|
+
apiFilterRadius.current = nearFilterValue.radius;
|
|
373
|
+
// only overwrite radius from filter if display options are enabled
|
|
374
|
+
const radius =
|
|
375
|
+
showDistanceOptions && selectedDistanceMeters
|
|
376
|
+
? selectedDistanceMeters
|
|
377
|
+
: nearFilterValue.radius;
|
|
378
|
+
locationFilter = buildNearLocationFilterFromPrevious(
|
|
379
|
+
nearFilterValue,
|
|
380
|
+
newDisplayName,
|
|
381
|
+
radius
|
|
382
|
+
);
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
case Matcher.Equals: {
|
|
386
|
+
apiFilterRadius.current = null;
|
|
387
|
+
locationFilter = buildEqualsLocationFilter(filter, newDisplayName);
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
default: {
|
|
391
|
+
throw new Error(`Unsupported matcher type: ${filter.matcher}`);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
searchActions.setOffset(0);
|
|
396
|
+
searchActions.setStaticFilters([locationFilter, openNowFilter]);
|
|
397
|
+
searchActions.executeVerticalQuery();
|
|
398
|
+
setSearchState("loading");
|
|
399
|
+
updateLocationQuery(newDisplayName);
|
|
400
|
+
setShowCurrentLocationButton(true);
|
|
401
|
+
if (
|
|
402
|
+
nearFilterValue?.lat &&
|
|
403
|
+
nearFilterValue?.lng &&
|
|
404
|
+
areValidCoordinates(nearFilterValue.lat, nearFilterValue.lng)
|
|
405
|
+
) {
|
|
406
|
+
setMapCenter({
|
|
407
|
+
latitude: nearFilterValue.lat,
|
|
408
|
+
longitude: nearFilterValue.lng,
|
|
409
|
+
});
|
|
410
|
+
setMapRadius(nearFilterValue.radius);
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
const searchLoading: boolean | undefined = useSearchState(
|
|
415
|
+
(state) => state.searchStatus.isLoading
|
|
416
|
+
);
|
|
417
|
+
const [searchState, setSearchState] =
|
|
418
|
+
React.useState<SearchState>("not started");
|
|
419
|
+
|
|
420
|
+
React.useEffect(() => {
|
|
421
|
+
if (!searchLoading && searchState === "loading") {
|
|
422
|
+
setSearchState("complete");
|
|
423
|
+
}
|
|
424
|
+
}, [searchLoading, searchState]);
|
|
425
|
+
|
|
426
|
+
React.useEffect(() => {
|
|
427
|
+
if (selectedDistanceOption === null) {
|
|
428
|
+
setSelectedDistanceMeters(null);
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
setSelectedDistanceMeters(toMeters(selectedDistanceOption, preferredUnit));
|
|
433
|
+
}, [preferredUnit, selectedDistanceOption]);
|
|
434
|
+
|
|
435
|
+
const resultsRef = React.useRef<Array<HTMLDivElement | null>>([]);
|
|
436
|
+
const resultsContainer = React.useRef<HTMLDivElement>(null);
|
|
437
|
+
const [mobileResults, setMobileResults] = React.useState<Result<Location>[]>(
|
|
438
|
+
[]
|
|
439
|
+
);
|
|
440
|
+
// Tracks the selected pin index to highlight the corresponding result card.
|
|
441
|
+
const [selectedResultIndex, setSelectedResultIndex] = React.useState<
|
|
442
|
+
number | null
|
|
443
|
+
>(null);
|
|
444
|
+
|
|
445
|
+
const setResultsRef = React.useCallback((index: number) => {
|
|
446
|
+
if (!resultsRef?.current) return null;
|
|
447
|
+
return (result: HTMLDivElement) => (resultsRef.current[index] = result);
|
|
448
|
+
}, []);
|
|
449
|
+
|
|
450
|
+
const scrollToResult = React.useCallback(
|
|
451
|
+
(result: Result<Location> | undefined) => {
|
|
452
|
+
if (result) {
|
|
453
|
+
if (typeof result.index === "number") {
|
|
454
|
+
setSelectedResultIndex(result.index);
|
|
455
|
+
}
|
|
456
|
+
let scrollPos = 0;
|
|
457
|
+
// the search results that are listed above this result
|
|
458
|
+
const previousResultsRef = resultsRef.current.filter(
|
|
459
|
+
(r, index) => r && result.index && index < result.index
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
// sum up the height of all search results that are listed above this result
|
|
463
|
+
if (previousResultsRef.length > 0) {
|
|
464
|
+
scrollPos = previousResultsRef
|
|
465
|
+
.map((elem) => elem?.scrollHeight ?? 0)
|
|
466
|
+
.reduce((total, height) => total + height);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
resultsContainer.current?.scroll({
|
|
470
|
+
top: scrollPos,
|
|
471
|
+
behavior: "smooth",
|
|
472
|
+
});
|
|
473
|
+
} else {
|
|
474
|
+
setSelectedResultIndex(null);
|
|
475
|
+
}
|
|
476
|
+
},
|
|
477
|
+
[]
|
|
478
|
+
);
|
|
479
|
+
|
|
480
|
+
const markerOptionsOverride = React.useCallback(
|
|
481
|
+
(selected: boolean): MapMarkerOptions => {
|
|
482
|
+
return {
|
|
483
|
+
offset: (selected ? [0, -21] : [0, -14]) as [number, number],
|
|
484
|
+
};
|
|
485
|
+
},
|
|
486
|
+
[]
|
|
487
|
+
);
|
|
488
|
+
|
|
489
|
+
const getResultCardProps = React.useCallback(
|
|
490
|
+
(entityType?: LocatorEntityType) => {
|
|
491
|
+
const existingConfig = (resultCardConfigs ?? []).find(
|
|
492
|
+
(item) => item.props.entityType === entityType
|
|
493
|
+
);
|
|
494
|
+
if (existingConfig) {
|
|
495
|
+
return existingConfig.props;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
return DEFAULT_LOCATOR_RESULT_CARD_PROPS;
|
|
499
|
+
},
|
|
500
|
+
[resultCardConfigs]
|
|
501
|
+
);
|
|
502
|
+
|
|
503
|
+
const CardComponent = React.useCallback(
|
|
504
|
+
(result: CardProps<Location>) => {
|
|
505
|
+
let resultCardProps = DEFAULT_LOCATOR_RESULT_CARD_PROPS;
|
|
506
|
+
const resultEntityType = result.result.entityType;
|
|
507
|
+
if (resultEntityType && isLocatorEntityType(resultEntityType)) {
|
|
508
|
+
resultCardProps = getResultCardProps(resultEntityType);
|
|
509
|
+
} else {
|
|
510
|
+
console.warn(
|
|
511
|
+
"Unexpected entityType from search result: ",
|
|
512
|
+
resultEntityType
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
return (
|
|
516
|
+
<LocatorResultCard
|
|
517
|
+
{...result}
|
|
518
|
+
resultCardProps={resultCardProps}
|
|
519
|
+
isSelected={result.result.index === selectedResultIndex}
|
|
520
|
+
distanceDisplay={distanceDisplay}
|
|
521
|
+
searchLocationName={filterDisplayName}
|
|
522
|
+
/>
|
|
523
|
+
);
|
|
524
|
+
},
|
|
525
|
+
[
|
|
526
|
+
distanceDisplay,
|
|
527
|
+
filterDisplayName,
|
|
528
|
+
getResultCardProps,
|
|
529
|
+
selectedResultIndex,
|
|
530
|
+
]
|
|
531
|
+
);
|
|
532
|
+
|
|
533
|
+
const locationStylesConfig = React.useMemo(() => {
|
|
534
|
+
const config: LocationStyleConfig = {};
|
|
535
|
+
(locationStyles ?? []).forEach((locationStyle) => {
|
|
536
|
+
const entityType = locationStyle.entityType;
|
|
537
|
+
if (!entityType) return;
|
|
538
|
+
const iconValue =
|
|
539
|
+
locationStyle.pinIcon?.type === "icon"
|
|
540
|
+
? locationStyle.pinIcon.iconName
|
|
541
|
+
: undefined;
|
|
542
|
+
const customImageValue =
|
|
543
|
+
locationStyle.pinIcon?.type === "customImage"
|
|
544
|
+
? resolveLocalizedAssetImage(
|
|
545
|
+
locationStyle.pinIcon.image,
|
|
546
|
+
i18n.language
|
|
547
|
+
)
|
|
548
|
+
: undefined;
|
|
549
|
+
const customImageUrl = customImageValue?.url?.trim();
|
|
550
|
+
config[entityType] = {
|
|
551
|
+
color: locationStyle.pinColor,
|
|
552
|
+
icon:
|
|
553
|
+
typeof iconValue === "string" ? makiIconMap[iconValue] : undefined,
|
|
554
|
+
customImage: customImageUrl
|
|
555
|
+
? {
|
|
556
|
+
url: customImageUrl,
|
|
557
|
+
width: locationStyle.pinIcon?.width,
|
|
558
|
+
aspectRatio: locationStyle.pinIcon?.aspectRatio,
|
|
559
|
+
}
|
|
560
|
+
: undefined,
|
|
561
|
+
};
|
|
562
|
+
});
|
|
563
|
+
return config;
|
|
564
|
+
}, [i18n.language, locationStyles]);
|
|
565
|
+
|
|
566
|
+
const initialMapCenter = React.useMemo(
|
|
567
|
+
() => getConfiguredMapCenterOrDefault(mapStartingLocation),
|
|
568
|
+
[mapStartingLocation]
|
|
569
|
+
);
|
|
570
|
+
const [centerCoords, setCenterCoords] =
|
|
571
|
+
React.useState<Coordinate>(initialMapCenter);
|
|
572
|
+
const [isInitialMapLocationResolved, setIsInitialMapLocationResolved] =
|
|
573
|
+
React.useState(false);
|
|
574
|
+
const canShowMoreMobileResults =
|
|
575
|
+
isMobile && mobileResults.length < resultCount;
|
|
576
|
+
|
|
577
|
+
const mapProps = React.useMemo(
|
|
578
|
+
() => ({
|
|
579
|
+
mapStyle,
|
|
580
|
+
centerCoords,
|
|
581
|
+
onDragHandler: handleDrag,
|
|
582
|
+
scrollToResult,
|
|
583
|
+
markerOptionsOverride,
|
|
584
|
+
locationStyleConfig: locationStylesConfig,
|
|
585
|
+
}),
|
|
586
|
+
[
|
|
587
|
+
centerCoords,
|
|
588
|
+
handleDrag,
|
|
589
|
+
mapStyle,
|
|
590
|
+
markerOptionsOverride,
|
|
591
|
+
scrollToResult,
|
|
592
|
+
locationStylesConfig,
|
|
593
|
+
]
|
|
594
|
+
);
|
|
595
|
+
|
|
596
|
+
React.useEffect(() => {
|
|
597
|
+
let isCancelled = false;
|
|
598
|
+
const queryParams = new URLSearchParams(window.location.search);
|
|
599
|
+
const initialLocationParam = queryParams.has(LOCATION_QUERY_KEY)
|
|
600
|
+
? queryParams.get(LOCATION_QUERY_KEY)
|
|
601
|
+
: queryParams.get(INITIAL_LOCATION_KEY);
|
|
602
|
+
|
|
603
|
+
const resolveLocationAndSearch = async () => {
|
|
604
|
+
setIsInitialMapLocationResolved(false);
|
|
605
|
+
setCenterCoords(initialMapCenter);
|
|
606
|
+
setMapCenter(initialMapCenter);
|
|
607
|
+
|
|
608
|
+
const radius =
|
|
609
|
+
showDistanceOptions && selectedDistanceMeters
|
|
610
|
+
? selectedDistanceMeters
|
|
611
|
+
: toMeters(DEFAULT_RADIUS, preferredUnit);
|
|
612
|
+
// default location filter to configured starting location or NYC
|
|
613
|
+
let initialLocationFilter = buildNearLocationFilterFromCoords(
|
|
614
|
+
initialMapCenter.latitude,
|
|
615
|
+
initialMapCenter.longitude,
|
|
616
|
+
radius
|
|
617
|
+
);
|
|
618
|
+
const doSearch = () => {
|
|
619
|
+
if (isCancelled) {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
searchActions.setVerticalLimit(RESULTS_LIMIT);
|
|
623
|
+
searchActions.setOffset(0);
|
|
624
|
+
searchActions.setStaticFilters(
|
|
625
|
+
urlNavigationVersion === 0
|
|
626
|
+
? [initialLocationFilter]
|
|
627
|
+
: [initialLocationFilter, openNowFilter]
|
|
628
|
+
);
|
|
629
|
+
searchActions.executeVerticalQuery();
|
|
630
|
+
setSearchState("loading");
|
|
631
|
+
if (
|
|
632
|
+
initialLocationFilter.filter.kind === "fieldValue" &&
|
|
633
|
+
initialLocationFilter.filter.matcher === Matcher.Near
|
|
634
|
+
) {
|
|
635
|
+
const filterValue = initialLocationFilter.filter
|
|
636
|
+
.value as NearFilterValue;
|
|
637
|
+
apiFilterRadius.current = filterValue.radius;
|
|
638
|
+
const nextCenterCoords: Coordinate = {
|
|
639
|
+
longitude: filterValue.lng,
|
|
640
|
+
latitude: filterValue.lat,
|
|
641
|
+
};
|
|
642
|
+
if (
|
|
643
|
+
!isCancelled &&
|
|
644
|
+
areValidCoordinates(
|
|
645
|
+
nextCenterCoords.latitude,
|
|
646
|
+
nextCenterCoords.longitude
|
|
647
|
+
)
|
|
648
|
+
) {
|
|
649
|
+
setCenterCoords(nextCenterCoords);
|
|
650
|
+
setMapCenter(nextCenterCoords);
|
|
651
|
+
setMapRadius(filterValue.radius);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
if (!isCancelled) {
|
|
655
|
+
setIsInitialMapLocationResolved(true);
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
const foundStartingLocationFromQueryParam = async (
|
|
660
|
+
queryParam: string
|
|
661
|
+
): Promise<boolean> => {
|
|
662
|
+
return searchActions
|
|
663
|
+
.executeFilterSearch(queryParam, false, [
|
|
664
|
+
{
|
|
665
|
+
fieldApiName: LOCATION_FIELD,
|
|
666
|
+
entityType: entityTypes[0] ?? DEFAULT_ENTITY_TYPE,
|
|
667
|
+
fetchEntities: false,
|
|
668
|
+
},
|
|
669
|
+
])
|
|
670
|
+
.then((response: FilterSearchResponse | undefined) => {
|
|
671
|
+
if (isCancelled) {
|
|
672
|
+
return false;
|
|
673
|
+
}
|
|
674
|
+
const firstResult = response?.sections[0]?.results[0];
|
|
675
|
+
const resultFilter = firstResult?.filter;
|
|
676
|
+
if (!firstResult || !resultFilter) {
|
|
677
|
+
return false;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
switch (resultFilter.matcher) {
|
|
681
|
+
case Matcher.Near: {
|
|
682
|
+
const filterFromResult = resultFilter.value as NearFilterValue;
|
|
683
|
+
initialLocationFilter = buildNearLocationFilterFromPrevious(
|
|
684
|
+
filterFromResult,
|
|
685
|
+
firstResult.value
|
|
686
|
+
);
|
|
687
|
+
apiFilterRadius.current = filterFromResult.radius;
|
|
688
|
+
return true;
|
|
689
|
+
}
|
|
690
|
+
case Matcher.Equals: {
|
|
691
|
+
initialLocationFilter = buildEqualsLocationFilter(
|
|
692
|
+
resultFilter,
|
|
693
|
+
firstResult.value
|
|
694
|
+
);
|
|
695
|
+
apiFilterRadius.current = null;
|
|
696
|
+
return true;
|
|
697
|
+
}
|
|
698
|
+
default: {
|
|
699
|
+
return false;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
})
|
|
703
|
+
.catch((e) => {
|
|
704
|
+
console.warn("Filter search for initial location failed:", e);
|
|
705
|
+
return false;
|
|
706
|
+
});
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
// 1. Resolve coordinates directly, or search for a named location.
|
|
710
|
+
// q always takes precedence over initialLocation
|
|
711
|
+
const coordinates = initialLocationParam
|
|
712
|
+
? parseCoordinateQuery(initialLocationParam)
|
|
713
|
+
: undefined;
|
|
714
|
+
if (coordinates) {
|
|
715
|
+
initialLocationFilter = buildNearLocationFilterFromCoords(
|
|
716
|
+
coordinates.lat,
|
|
717
|
+
coordinates.lng,
|
|
718
|
+
coordinates.radius,
|
|
719
|
+
t("customSearchArea", "Custom Search Area")
|
|
720
|
+
);
|
|
721
|
+
doSearch();
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
if (
|
|
725
|
+
initialLocationParam &&
|
|
726
|
+
(await foundStartingLocationFromQueryParam(initialLocationParam))
|
|
727
|
+
) {
|
|
728
|
+
doSearch();
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
if (isCancelled) {
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
try {
|
|
737
|
+
// 2. Try to get user location via Geolocation API
|
|
738
|
+
const location = await getUserLocation();
|
|
739
|
+
if (isCancelled) {
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
const lat = location.coords.latitude;
|
|
743
|
+
const lng = location.coords.longitude;
|
|
744
|
+
setShowCurrentLocationButton(true);
|
|
745
|
+
|
|
746
|
+
// Try to reverse-geocode the coordinates to a human-readable place name using Mapbox
|
|
747
|
+
let displayName: string | undefined;
|
|
748
|
+
try {
|
|
749
|
+
if (mapboxApiKey) {
|
|
750
|
+
const lang =
|
|
751
|
+
(streamDocument.locale as string) ||
|
|
752
|
+
(typeof navigator !== "undefined"
|
|
753
|
+
? navigator.language
|
|
754
|
+
: undefined) ||
|
|
755
|
+
"en";
|
|
756
|
+
const url = `https://api.mapbox.com/geocoding/v5/mapbox.places/${lng},${lat}.json?access_token=${mapboxApiKey}&types=place,region,country&limit=1&language=${encodeURIComponent(
|
|
757
|
+
lang
|
|
758
|
+
)}`;
|
|
759
|
+
|
|
760
|
+
const res = await fetch(url);
|
|
761
|
+
if (res.ok) {
|
|
762
|
+
const data = await res.json();
|
|
763
|
+
const feature = data.features && data.features[0];
|
|
764
|
+
displayName = feature?.place_name || undefined;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
} catch (e) {
|
|
768
|
+
console.warn("Reverse geocoding failed:", e);
|
|
769
|
+
} finally {
|
|
770
|
+
initialLocationFilter = buildNearLocationFilterFromCoords(
|
|
771
|
+
lat,
|
|
772
|
+
lng,
|
|
773
|
+
radius,
|
|
774
|
+
displayName
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
} catch {
|
|
778
|
+
// Fall back to configured starting location or default center.
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
doSearch();
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
resolveLocationAndSearch().catch((e) => {
|
|
785
|
+
if (!isCancelled) {
|
|
786
|
+
setIsInitialMapLocationResolved(true);
|
|
787
|
+
}
|
|
788
|
+
console.error("Failed perform search:", e);
|
|
789
|
+
});
|
|
790
|
+
return () => {
|
|
791
|
+
isCancelled = true;
|
|
792
|
+
};
|
|
793
|
+
}, [urlNavigationVersion, initialMapCenter, searchActions]);
|
|
794
|
+
|
|
795
|
+
const handleOpenNowClick = (selected: boolean) => {
|
|
796
|
+
if (selected === isOpenNowSelected) {
|
|
797
|
+
// Prevents us from trying to set Open Now filter to false when it's not set
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
searchActions.setFilterOption({
|
|
801
|
+
filter: {
|
|
802
|
+
kind: "fieldValue",
|
|
803
|
+
fieldId: HOURS_FIELD,
|
|
804
|
+
matcher: Matcher.OpenAt,
|
|
805
|
+
value: "now",
|
|
806
|
+
},
|
|
807
|
+
selected,
|
|
808
|
+
displayName: t("openNow", "Open Now"),
|
|
809
|
+
});
|
|
810
|
+
setIsOpenNowSelected(selected);
|
|
811
|
+
searchActions.setOffset(0);
|
|
812
|
+
executeSearch(searchActions);
|
|
813
|
+
};
|
|
814
|
+
|
|
815
|
+
const currentOffset = useSearchState((state) => state.vertical.offset);
|
|
816
|
+
const previousOffset = React.useRef<number | undefined>(undefined);
|
|
817
|
+
const prevIsMobile = React.useRef(isMobile);
|
|
818
|
+
|
|
819
|
+
// Scroll to top when pagination changes
|
|
820
|
+
React.useEffect(() => {
|
|
821
|
+
if (
|
|
822
|
+
!isMobile &&
|
|
823
|
+
currentOffset !== previousOffset.current &&
|
|
824
|
+
previousOffset.current !== undefined
|
|
825
|
+
) {
|
|
826
|
+
resultsContainer.current?.scroll({
|
|
827
|
+
top: 0,
|
|
828
|
+
behavior: "smooth",
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
previousOffset.current = currentOffset;
|
|
832
|
+
}, [currentOffset, isMobile]);
|
|
833
|
+
|
|
834
|
+
React.useEffect(() => {
|
|
835
|
+
const switchedToMobile = isMobile && !prevIsMobile.current;
|
|
836
|
+
|
|
837
|
+
prevIsMobile.current = isMobile;
|
|
838
|
+
|
|
839
|
+
if (
|
|
840
|
+
!switchedToMobile ||
|
|
841
|
+
searchLoading !== false ||
|
|
842
|
+
(currentOffset ?? 0) === 0
|
|
843
|
+
) {
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// Always reload from offset 0 if switching to mobile
|
|
848
|
+
setMobileResults([]);
|
|
849
|
+
searchActions.setOffset(0);
|
|
850
|
+
executeSearch(searchActions);
|
|
851
|
+
setSearchState("loading");
|
|
852
|
+
}, [currentOffset, isMobile, searchActions, searchLoading]);
|
|
853
|
+
|
|
854
|
+
React.useEffect(() => {
|
|
855
|
+
if (!isMobile || searchLoading !== false) {
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
setMobileResults((previousResults) => {
|
|
860
|
+
// Mobile keeps a single growing list: later offsets append, while
|
|
861
|
+
// offset 0 replaces the list after a fresh search.
|
|
862
|
+
return (currentOffset ?? 0) > 0 && searchResults.length > 0
|
|
863
|
+
? [...previousResults, ...searchResults]
|
|
864
|
+
: searchResults;
|
|
865
|
+
});
|
|
866
|
+
}, [currentOffset, isMobile, searchLoading, searchResults]);
|
|
867
|
+
|
|
868
|
+
const handleDistanceClick = (
|
|
869
|
+
distance: number,
|
|
870
|
+
distanceUnit: "mile" | "kilometer"
|
|
871
|
+
) => {
|
|
872
|
+
const existingFilters = searchFilters.static || [];
|
|
873
|
+
let updatedFilters: SelectableStaticFilter[];
|
|
874
|
+
const distanceInMeters = toMeters(distance, distanceUnit);
|
|
875
|
+
if (selectedDistanceOption === distance) {
|
|
876
|
+
setSelectedDistanceMeters(null);
|
|
877
|
+
setSelectedDistanceOption(null);
|
|
878
|
+
// revert to API radius (or default if none was found) if user clicks the same distance again
|
|
879
|
+
updatedFilters = updateRadiusInNearFiltersOnLocationField(
|
|
880
|
+
existingFilters,
|
|
881
|
+
apiFilterRadius.current ?? toMeters(DEFAULT_RADIUS, preferredUnit)
|
|
882
|
+
);
|
|
883
|
+
} else {
|
|
884
|
+
setSelectedDistanceOption(distance);
|
|
885
|
+
updatedFilters = updateRadiusInNearFiltersOnLocationField(
|
|
886
|
+
existingFilters,
|
|
887
|
+
distanceInMeters
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
searchActions.setStaticFilters(updatedFilters);
|
|
891
|
+
searchActions.setOffset(0);
|
|
892
|
+
executeSearch(searchActions);
|
|
893
|
+
};
|
|
894
|
+
|
|
895
|
+
const handleClearFiltersClick = () => {
|
|
896
|
+
const existingFilters = searchFilters.static || [];
|
|
897
|
+
// revert to API radius (or default if none was found)
|
|
898
|
+
const partiallyUpdatedFilters = updateRadiusInNearFiltersOnLocationField(
|
|
899
|
+
existingFilters,
|
|
900
|
+
apiFilterRadius.current ?? toMeters(DEFAULT_RADIUS, preferredUnit)
|
|
901
|
+
);
|
|
902
|
+
const updatedFilters = deselectOpenNowFilters(partiallyUpdatedFilters);
|
|
903
|
+
|
|
904
|
+
// Both open now and distance filters must be updated in the same setStaticFilters call to
|
|
905
|
+
// avoid problems due to the asynchronous nature of state updates.
|
|
906
|
+
searchActions.setStaticFilters(updatedFilters);
|
|
907
|
+
searchActions.resetFacets();
|
|
908
|
+
// Execute search to update AppliedFilters components
|
|
909
|
+
searchActions.setOffset(0);
|
|
910
|
+
executeSearch(searchActions);
|
|
911
|
+
setSelectedDistanceMeters(null);
|
|
912
|
+
setSelectedDistanceOption(null);
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
// If something else causes the filters to update, check if the hours filter is still present
|
|
916
|
+
// and toggle off the Open Now toggle if not.
|
|
917
|
+
React.useEffect(() => {
|
|
918
|
+
setIsOpenNowSelected(
|
|
919
|
+
searchFilters.static
|
|
920
|
+
? !!searchFilters.static.find((staticFilter) => {
|
|
921
|
+
return (
|
|
922
|
+
staticFilter.filter.kind === "fieldValue" &&
|
|
923
|
+
staticFilter.filter.fieldId === HOURS_FIELD &&
|
|
924
|
+
staticFilter.selected === true
|
|
925
|
+
);
|
|
926
|
+
})
|
|
927
|
+
: false
|
|
928
|
+
);
|
|
929
|
+
}, [searchFilters]);
|
|
930
|
+
|
|
931
|
+
const hasFacetOptions =
|
|
932
|
+
(
|
|
933
|
+
useSearchState((state) =>
|
|
934
|
+
state.filters.facets?.filter((f) => f.options.length)
|
|
935
|
+
) ?? []
|
|
936
|
+
).length > 0;
|
|
937
|
+
const hasFilterModalToggle =
|
|
938
|
+
openNowButton || showDistanceOptions || hasFacetOptions;
|
|
939
|
+
const filterAccentColorCssVariable =
|
|
940
|
+
getThemeColorCssValue(accentColor?.selectedColor) ??
|
|
941
|
+
"var(--colors-palette-primary-dark)";
|
|
942
|
+
const [showFilterModal, setShowFilterModal] = React.useState(false);
|
|
943
|
+
const filterToggleButtonRef = React.useRef<HTMLButtonElement>(null);
|
|
944
|
+
const filterModalCloseButtonRef = React.useRef<HTMLButtonElement>(null);
|
|
945
|
+
const hasOpenedFilterModalRef = React.useRef(false);
|
|
946
|
+
const resolvedHeading =
|
|
947
|
+
(pageHeading?.title &&
|
|
948
|
+
resolveComponentData(pageHeading.title, i18n.language, streamDocument)) ||
|
|
949
|
+
t("findALocation", "Find a Location");
|
|
950
|
+
|
|
951
|
+
const requireMapOptIn: boolean = streamDocument.__?.visualEditorConfig
|
|
952
|
+
? JSON.parse(streamDocument.__?.visualEditorConfig)?.requireMapOptIn
|
|
953
|
+
: false;
|
|
954
|
+
// If no opt-in is required, the map is already enabled.
|
|
955
|
+
const [mapEnabled, setMapEnabled] = React.useState(!requireMapOptIn);
|
|
956
|
+
// Adds unified [enable|disable]Map functions to the window.
|
|
957
|
+
useEffect(() => {
|
|
958
|
+
(window as any).enableMap = () => setMapEnabled(true);
|
|
959
|
+
(window as any).disableMap = () => setMapEnabled(false);
|
|
960
|
+
|
|
961
|
+
return () => {
|
|
962
|
+
delete (window as any).enableMap;
|
|
963
|
+
delete (window as any).disableMap;
|
|
964
|
+
};
|
|
965
|
+
}, []);
|
|
966
|
+
|
|
967
|
+
useEffect(() => {
|
|
968
|
+
if (showFilterModal) {
|
|
969
|
+
hasOpenedFilterModalRef.current = true;
|
|
970
|
+
filterModalCloseButtonRef.current?.focus();
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
if (hasOpenedFilterModalRef.current) {
|
|
975
|
+
filterToggleButtonRef.current?.focus();
|
|
976
|
+
}
|
|
977
|
+
}, [showFilterModal]);
|
|
978
|
+
|
|
979
|
+
return (
|
|
980
|
+
<div className="components flex h-screen w-full mx-auto">
|
|
981
|
+
{/* Left Section: FilterSearch + Results. Full width for small screens */}
|
|
982
|
+
<div
|
|
983
|
+
className="relative h-screen w-full md:w-2/5 lg:w-[40rem] flex flex-col md:min-w-[24rem]"
|
|
984
|
+
id="locatorLeftDiv"
|
|
985
|
+
>
|
|
986
|
+
<div className="px-8 py-6 gap-4 flex flex-col">
|
|
987
|
+
<Heading level={1} color={pageHeading?.color}>
|
|
988
|
+
{resolvedHeading}
|
|
989
|
+
</Heading>
|
|
990
|
+
<FilterSearch
|
|
991
|
+
searchFields={[
|
|
992
|
+
{
|
|
993
|
+
fieldApiName: LOCATION_FIELD,
|
|
994
|
+
entityType: entityTypes[0] ?? DEFAULT_ENTITY_TYPE,
|
|
995
|
+
},
|
|
996
|
+
]}
|
|
997
|
+
onSelect={handleFilterSelect}
|
|
998
|
+
placeholder={t("searchHere", "Search here...")}
|
|
999
|
+
ariaLabel={t("findALocation", "Find a Location")}
|
|
1000
|
+
customCssClasses={{
|
|
1001
|
+
filterSearchContainer: "font-body-fontFamily",
|
|
1002
|
+
focusedOption: "bg-gray-200 hover:bg-gray-200 block",
|
|
1003
|
+
option: "hover:bg-gray-100 px-4 py-3",
|
|
1004
|
+
inputElement:
|
|
1005
|
+
"rounded-md p-4 h-11 font-body-fontFamily font-body-fontWeight text-body-fontSize placeholder:text-gray-700",
|
|
1006
|
+
currentLocationButton:
|
|
1007
|
+
"h-7 w-7 font-body-fontFamily font-body-fontWeight text-body-fontSize text-palette-primary-dark",
|
|
1008
|
+
label:
|
|
1009
|
+
"font-body-fontFamily font-body-fontWeight text-body-fontSize text-palette-primary-dark",
|
|
1010
|
+
}}
|
|
1011
|
+
showCurrentLocationButton={showCurrentLocationButton}
|
|
1012
|
+
geolocationProps={{
|
|
1013
|
+
handleClick: handleCurrentLocationClick,
|
|
1014
|
+
radius:
|
|
1015
|
+
preferredUnit === "mile"
|
|
1016
|
+
? DEFAULT_RADIUS
|
|
1017
|
+
: toMiles(DEFAULT_RADIUS), // this component uses miles, not meters
|
|
1018
|
+
}}
|
|
1019
|
+
/>
|
|
1020
|
+
</div>
|
|
1021
|
+
<div className="relative flex-1 flex flex-col min-h-0">
|
|
1022
|
+
<div className="px-8 py-4 text-body-fontSize border-y border-gray-300 inline-block">
|
|
1023
|
+
<div className="flex flex-row justify-between" id="levelWithModal">
|
|
1024
|
+
<ResultsCountSummary
|
|
1025
|
+
searchState={searchState}
|
|
1026
|
+
resultCount={resultCount}
|
|
1027
|
+
selectedDistanceOption={selectedDistanceOption}
|
|
1028
|
+
filterDisplayName={filterDisplayName}
|
|
1029
|
+
/>
|
|
1030
|
+
{hasFilterModalToggle && (
|
|
1031
|
+
<button
|
|
1032
|
+
ref={filterToggleButtonRef}
|
|
1033
|
+
className="inline-flex justify-between items-center gap-2 bg-white font-bold font-body-fontFamily text-body-sm-fontSize"
|
|
1034
|
+
style={{ color: filterAccentColorCssVariable }}
|
|
1035
|
+
onClick={() => setShowFilterModal((prev) => !prev)}
|
|
1036
|
+
aria-haspopup="dialog"
|
|
1037
|
+
aria-expanded={showFilterModal}
|
|
1038
|
+
aria-controls="locator-filter-modal"
|
|
1039
|
+
>
|
|
1040
|
+
{t("filter", "Filter")}
|
|
1041
|
+
<FaSlidersH />
|
|
1042
|
+
</button>
|
|
1043
|
+
)}
|
|
1044
|
+
</div>
|
|
1045
|
+
<div className="flex flex-row justify-between">
|
|
1046
|
+
<AppliedFilters
|
|
1047
|
+
hiddenFields={[LOCATION_FIELD, COUNTRY_CODE_FIELD]}
|
|
1048
|
+
customCssClasses={{
|
|
1049
|
+
removableFilter:
|
|
1050
|
+
"text-md font-normal mt-2 mb-0 font-body-fontFamily",
|
|
1051
|
+
clearAllButton: "hidden",
|
|
1052
|
+
appliedFiltersContainer: "mt-0 mb-0",
|
|
1053
|
+
}}
|
|
1054
|
+
/>
|
|
1055
|
+
</div>
|
|
1056
|
+
</div>
|
|
1057
|
+
{resultCount > 0 && (
|
|
1058
|
+
<div
|
|
1059
|
+
id="innerDiv"
|
|
1060
|
+
className="md:flex-1 md:overflow-y-auto"
|
|
1061
|
+
ref={resultsContainer}
|
|
1062
|
+
>
|
|
1063
|
+
{isMobile ? (
|
|
1064
|
+
<MobileLocatorResultsSection
|
|
1065
|
+
CardComponent={CardComponent}
|
|
1066
|
+
results={mobileResults}
|
|
1067
|
+
hasMoreResults={canShowMoreMobileResults}
|
|
1068
|
+
handleShowMoreResults={() => {
|
|
1069
|
+
if (searchLoading || mobileResults.length >= resultCount) {
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
searchActions.setOffset(mobileResults.length);
|
|
1074
|
+
executeSearch(searchActions);
|
|
1075
|
+
setSearchState("loading");
|
|
1076
|
+
}}
|
|
1077
|
+
/>
|
|
1078
|
+
) : (
|
|
1079
|
+
<VerticalResults
|
|
1080
|
+
CardComponent={CardComponent}
|
|
1081
|
+
setResultsRef={setResultsRef}
|
|
1082
|
+
/>
|
|
1083
|
+
)}
|
|
1084
|
+
</div>
|
|
1085
|
+
)}
|
|
1086
|
+
{!isMobile && resultCount > RESULTS_LIMIT && (
|
|
1087
|
+
<div className="border-t border-gray-300 pt-4">
|
|
1088
|
+
<Pagination
|
|
1089
|
+
customCssClasses={{
|
|
1090
|
+
selectedLabel:
|
|
1091
|
+
"bg-palette-primary text-palette-primary-contrast border-palette-primary",
|
|
1092
|
+
}}
|
|
1093
|
+
/>
|
|
1094
|
+
</div>
|
|
1095
|
+
)}
|
|
1096
|
+
<FilterModal
|
|
1097
|
+
showFilterModal={showFilterModal}
|
|
1098
|
+
showOpenNowOption={openNowButton}
|
|
1099
|
+
isOpenNowSelected={isOpenNowSelected}
|
|
1100
|
+
handleOpenNowClick={handleOpenNowClick}
|
|
1101
|
+
showDistanceOptions={showDistanceOptions}
|
|
1102
|
+
selectedDistanceOption={selectedDistanceOption}
|
|
1103
|
+
handleDistanceClick={handleDistanceClick}
|
|
1104
|
+
handleCloseModalClick={() => setShowFilterModal(false)}
|
|
1105
|
+
handleClearFiltersClick={handleClearFiltersClick}
|
|
1106
|
+
accentColorCssValue={filterAccentColorCssVariable}
|
|
1107
|
+
closeButtonRef={filterModalCloseButtonRef}
|
|
1108
|
+
keywordsDisplayName={keywordsDisplayName}
|
|
1109
|
+
/>
|
|
1110
|
+
</div>
|
|
1111
|
+
</div>
|
|
1112
|
+
|
|
1113
|
+
{/* Right Section: Map. Hidden for small screens */}
|
|
1114
|
+
<div id="locatorMapDiv" className="md:flex-1 md:flex hidden relative">
|
|
1115
|
+
{mapEnabled && isInitialMapLocationResolved && (
|
|
1116
|
+
<LocatorMap {...mapProps} />
|
|
1117
|
+
)}
|
|
1118
|
+
{mapEnabled && !isInitialMapLocationResolved && (
|
|
1119
|
+
<LoadingMapPlaceholder />
|
|
1120
|
+
)}
|
|
1121
|
+
{!mapEnabled && (
|
|
1122
|
+
<div className="flex items-center justify-center w-full h-full bg-gray-100">
|
|
1123
|
+
<div className="p-6">
|
|
1124
|
+
<Body
|
|
1125
|
+
className="text-gray-700 font-bold text-center"
|
|
1126
|
+
variant="lg"
|
|
1127
|
+
>
|
|
1128
|
+
{t(
|
|
1129
|
+
"mapRequiresOptIn",
|
|
1130
|
+
"This map can only be displayed if cookies are enabled"
|
|
1131
|
+
)}
|
|
1132
|
+
</Body>
|
|
1133
|
+
<div className="flex justify-center p-2">
|
|
1134
|
+
<Button
|
|
1135
|
+
onClick={() => setMapEnabled(true)}
|
|
1136
|
+
className="py-2 px-4 basis-full sm:w-auto justify-center"
|
|
1137
|
+
>
|
|
1138
|
+
{t("enableCookies", "Enable Cookies")}
|
|
1139
|
+
</Button>
|
|
1140
|
+
</div>
|
|
1141
|
+
</div>
|
|
1142
|
+
</div>
|
|
1143
|
+
)}
|
|
1144
|
+
{showSearchAreaButton && (
|
|
1145
|
+
<div className="absolute top-10 left-0 right-0 flex justify-center">
|
|
1146
|
+
<Button
|
|
1147
|
+
onClick={handleSearchAreaClick}
|
|
1148
|
+
className="py-2 px-4 shadow-xl"
|
|
1149
|
+
>
|
|
1150
|
+
<Body>{t("searchThisArea", "Search This Area")}</Body>
|
|
1151
|
+
</Button>
|
|
1152
|
+
</div>
|
|
1153
|
+
)}
|
|
1154
|
+
</div>
|
|
1155
|
+
</div>
|
|
1156
|
+
);
|
|
1157
|
+
};
|