@abcagency/hc-ui-components 1.3.58 → 1.3.60
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/components/HireControlMap.js +11 -1
- package/dist/components/HireControlMap.js.map +1 -1
- package/dist/components/containers/accordions/filter-item-container.js.map +1 -1
- package/dist/components/containers/filter/commute-container.js +1 -1
- package/dist/components/containers/filter/commute-container.js.map +1 -1
- package/dist/components/containers/filter/filter-container.js.map +1 -1
- package/dist/components/containers/filter/filter-item-container.js.map +1 -1
- package/dist/components/containers/filter/location-container.js.map +1 -1
- package/dist/components/containers/filter/points-of-interest-container.js.map +1 -1
- package/dist/components/containers/filter/points-of-interest-radio-item-container.js.map +1 -1
- package/dist/components/containers/filter/search-container.js.map +1 -1
- package/dist/components/containers/jobListing/listing-details-container.js +5 -1
- package/dist/components/containers/jobListing/listing-details-container.js.map +1 -1
- package/dist/components/containers/list/item-list-container.js.map +1 -1
- package/dist/components/containers/maps/info-window-content-container.js.map +1 -1
- package/dist/components/containers/maps/map-container.js +1 -1
- package/dist/components/containers/maps/map-list-container.js.map +1 -1
- package/dist/components/containers/maps/map-marker-container.js +1 -1
- package/dist/components/containers/maps/map-marker-container.js.map +1 -1
- package/dist/components/modules/accordions/default.js +2 -2
- package/dist/components/modules/accordions/filterItem.js.map +1 -1
- package/dist/components/modules/accordions/filters.js.map +1 -1
- package/dist/components/modules/buttons/button-group-apply.js +48 -54
- package/dist/components/modules/buttons/button-group-apply.js.map +1 -1
- package/dist/components/modules/buttons/default.js +2 -2
- package/dist/components/modules/cards/default.js +2 -2
- package/dist/components/modules/dialogs/apply-dialog.js +1 -1
- package/dist/components/modules/dialogs/apply-dialog.js.map +1 -1
- package/dist/components/modules/filter/commute.js +2 -2
- package/dist/components/modules/filter/commute.js.map +1 -1
- package/dist/components/modules/filter/index.js.map +1 -1
- package/dist/components/modules/filter/location.js.map +1 -1
- package/dist/components/modules/filter/radio-item.js.map +1 -1
- package/dist/components/modules/filter/search.js.map +1 -1
- package/dist/components/modules/filter/sort.js +2 -2
- package/dist/components/modules/grid.js +1 -1
- package/dist/components/modules/icon.js +1 -1
- package/dist/components/modules/jobListing/listing-details.js +8 -7
- package/dist/components/modules/jobListing/listing-details.js.map +1 -1
- package/dist/components/modules/list/field-mapper.js.map +1 -1
- package/dist/components/modules/list/header-item.js.map +1 -1
- package/dist/components/modules/list/header.js +1 -1
- package/dist/components/modules/list/item-expand-card/index.js +1 -1
- package/dist/components/modules/list/item-expand-card/index.js.map +1 -1
- package/dist/components/modules/list/item-expand-card/recruiter-contact-nav.js +38 -38
- package/dist/components/modules/list/item-expand-card/recruiter-details.js +40 -40
- package/dist/components/modules/list/item-expand-card/recruiter-headshot.js +20 -20
- package/dist/components/modules/list/item-list.js +3 -3
- package/dist/components/modules/list/item-list.js.map +1 -1
- package/dist/components/modules/list/list-item/list-item.js.map +1 -1
- package/dist/components/modules/maps/info-window-content.js.map +1 -1
- package/dist/components/modules/maps/map-list.js.map +1 -1
- package/dist/components/modules/maps/map-marker.js +1 -1
- package/dist/components/modules/maps/map-marker.js.map +1 -1
- package/dist/components/modules/maps/map.js +1 -1
- package/dist/components/modules/maps/place-marker.js +1 -1
- package/dist/components/modules/maps/tabs.js +1 -1
- package/dist/constants/eventTypes.js +1 -0
- package/dist/constants/eventTypes.js.map +1 -1
- package/dist/contexts/mapContext.js.map +1 -1
- package/dist/contexts/mapListContext.js +3 -1
- package/dist/contexts/mapListContext.js.map +1 -1
- package/dist/contexts/placesContext.js.map +1 -1
- package/dist/contexts/themeContext.js.map +1 -1
- package/dist/services/configService.js.map +1 -1
- package/dist/services/listingEntityService.js.map +1 -1
- package/dist/services/listingService.js.map +1 -1
- package/dist/services/recruiterService.js.map +1 -1
- package/dist/types/components/modules/buttons/button-group-apply.d.ts +4 -4
- package/dist/types/components/modules/jobListing/listing-details.d.ts +3 -1
- package/dist/types/constants/eventTypes.d.ts +1 -0
- package/dist/types/contexts/mapListContext.d.ts +4 -0
- package/dist/util/filterUtil.js +3 -3
- package/dist/util/filterUtil.js.map +1 -1
- package/dist/util/mapIconUtil.js.map +1 -1
- package/dist/util/mapUtil.js.map +1 -1
- package/package.json +90 -90
- package/src/.editorconfig +12 -12
- package/src/bundleIndex.js +14 -14
- package/src/components/HireControlMap.js +148 -142
- package/src/components/containers/accordions/filter-item-container.js +83 -83
- package/src/components/containers/filter/commute-container.js +89 -89
- package/src/components/containers/filter/filter-container.js +76 -76
- package/src/components/containers/filter/filter-item-container.js +117 -117
- package/src/components/containers/filter/location-container.js +45 -45
- package/src/components/containers/filter/points-of-interest-container.js +33 -33
- package/src/components/containers/filter/points-of-interest-radio-item-container.js +35 -35
- package/src/components/containers/filter/search-container.js +61 -61
- package/src/components/containers/jobListing/listing-details-container.js +3 -1
- package/src/components/containers/list/item-list-container.tsx +81 -81
- package/src/components/containers/maps/info-window-content-container.js +53 -53
- package/src/components/containers/maps/map-list-container.js +50 -50
- package/src/components/containers/maps/map-marker-container.js +78 -78
- package/src/components/modules/accordions/filterItem.js +27 -27
- package/src/components/modules/accordions/filters.js +32 -32
- package/src/components/modules/buttons/button-group-apply.js +115 -135
- package/src/components/modules/dialogs/apply-dialog.js +48 -48
- package/src/components/modules/filter/commute.js +108 -108
- package/src/components/modules/filter/index.js +55 -55
- package/src/components/modules/filter/location.js +51 -51
- package/src/components/modules/filter/radio-item.js +42 -42
- package/src/components/modules/filter/search.js +79 -79
- package/src/components/modules/jobListing/listing-details.js +110 -108
- package/src/components/modules/list/field-mapper.js +130 -130
- package/src/components/modules/list/header-item.js +92 -92
- package/src/components/modules/list/item-expand-card/index.js +22 -22
- package/src/components/modules/list/item-list.tsx +117 -117
- package/src/components/modules/list/list-item/list-item.js +130 -130
- package/src/components/modules/maps/info-window-content.js +64 -64
- package/src/components/modules/maps/map-list.js +38 -38
- package/src/components/modules/maps/map-marker.js +29 -29
- package/src/constants/eventTypes.js +15 -14
- package/src/contexts/mapContext.tsx +129 -129
- package/src/contexts/mapListContext.tsx +326 -318
- package/src/contexts/placesContext.js +102 -102
- package/src/contexts/themeContext.js +40 -40
- package/src/services/configService.ts +16 -16
- package/src/services/listingEntityService.ts +16 -16
- package/src/services/listingService.ts +40 -40
- package/src/services/recruiterService.ts +18 -18
- package/src/styles/bundle.css +268 -268
- package/src/styles/index.css +33 -33
- package/src/types/Address.ts +7 -7
- package/src/types/ContentSection.ts +9 -9
- package/src/types/GetListingParams.ts +8 -8
- package/src/types/LatLng.ts +4 -4
- package/src/types/ListingEntity.ts +11 -11
- package/src/types/ListingFields.ts +25 -25
- package/src/types/Listings.ts +32 -32
- package/src/types/Recruiter.ts +9 -9
- package/src/types/SimilarListing.ts +24 -24
- package/src/types/config/Colors.ts +8 -8
- package/src/types/config/MapConfig.ts +31 -31
- package/src/types/config/PointsOfInterestConfig.ts +13 -13
- package/src/types/config/SearchConfig.ts +4 -4
- package/src/util/filterUtil.js +2 -1
- package/src/util/mapIconUtil.js +180 -180
- package/src/util/mapUtil.js +92 -92
- package/dist/types/contexts/themeContext.d.ts +0 -11
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import Tabs from '~/components/modules/maps/tabs';
|
|
3
|
-
|
|
4
|
-
const MapList = ({ showMap, loading, list, map, filter, mapPosition }) => {
|
|
5
|
-
return (
|
|
6
|
-
<>
|
|
7
|
-
<div
|
|
8
|
-
className={`
|
|
9
|
-
${showMap === false ? "md:hc-grid-rows-[100vh]" : "md:hc-grid-rows-[50vh_50vh]"}
|
|
10
|
-
md:hc-grid md:hc-pt-4 hc-overflow-hidden hc-relative bg-gray-100
|
|
11
|
-
`}
|
|
12
|
-
>
|
|
13
|
-
{mapPosition && mapPosition === 'top' && showMap ? (
|
|
14
|
-
<>
|
|
15
|
-
<div>{map}</div>
|
|
16
|
-
<div>{list}</div>
|
|
17
|
-
</>
|
|
18
|
-
) : (
|
|
19
|
-
<>
|
|
20
|
-
<div>{list}</div>
|
|
21
|
-
<div>{showMap && map}</div>
|
|
22
|
-
</>
|
|
23
|
-
)}
|
|
24
|
-
|
|
25
|
-
</div>
|
|
26
|
-
<div className="md:hc-hidden">
|
|
27
|
-
<Tabs
|
|
28
|
-
showMap={showMap}
|
|
29
|
-
list={list}
|
|
30
|
-
map={!loading && showMap && map}
|
|
31
|
-
filter={filter}
|
|
32
|
-
/>
|
|
33
|
-
</div>
|
|
34
|
-
</>
|
|
35
|
-
);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export default MapList;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Tabs from '~/components/modules/maps/tabs';
|
|
3
|
+
|
|
4
|
+
const MapList = ({ showMap, loading, list, map, filter, mapPosition }) => {
|
|
5
|
+
return (
|
|
6
|
+
<>
|
|
7
|
+
<div
|
|
8
|
+
className={`
|
|
9
|
+
${showMap === false ? "md:hc-grid-rows-[100vh]" : "md:hc-grid-rows-[50vh_50vh]"}
|
|
10
|
+
md:hc-grid md:hc-pt-4 hc-overflow-hidden hc-relative bg-gray-100
|
|
11
|
+
`}
|
|
12
|
+
>
|
|
13
|
+
{mapPosition && mapPosition === 'top' && showMap ? (
|
|
14
|
+
<>
|
|
15
|
+
<div>{map}</div>
|
|
16
|
+
<div>{list}</div>
|
|
17
|
+
</>
|
|
18
|
+
) : (
|
|
19
|
+
<>
|
|
20
|
+
<div>{list}</div>
|
|
21
|
+
<div>{showMap && map}</div>
|
|
22
|
+
</>
|
|
23
|
+
)}
|
|
24
|
+
|
|
25
|
+
</div>
|
|
26
|
+
<div className="md:hc-hidden">
|
|
27
|
+
<Tabs
|
|
28
|
+
showMap={showMap}
|
|
29
|
+
list={list}
|
|
30
|
+
map={!loading && showMap && map}
|
|
31
|
+
filter={filter}
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
34
|
+
</>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default MapList;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { MarkerF } from '@react-google-maps/api';
|
|
3
|
-
|
|
4
|
-
const MapMarker = ({
|
|
5
|
-
position,
|
|
6
|
-
title,
|
|
7
|
-
icon,
|
|
8
|
-
zIndex,
|
|
9
|
-
onLoad,
|
|
10
|
-
onClick,
|
|
11
|
-
clusterer,
|
|
12
|
-
children
|
|
13
|
-
}) => {
|
|
14
|
-
return (
|
|
15
|
-
<MarkerF
|
|
16
|
-
position={position}
|
|
17
|
-
title={title}
|
|
18
|
-
options={{ icon: icon }}
|
|
19
|
-
zIndex={zIndex}
|
|
20
|
-
onLoad={onLoad}
|
|
21
|
-
onClick={onClick}
|
|
22
|
-
clusterer={clusterer}
|
|
23
|
-
>
|
|
24
|
-
{children}
|
|
25
|
-
</MarkerF>
|
|
26
|
-
);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export default MapMarker;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MarkerF } from '@react-google-maps/api';
|
|
3
|
+
|
|
4
|
+
const MapMarker = ({
|
|
5
|
+
position,
|
|
6
|
+
title,
|
|
7
|
+
icon,
|
|
8
|
+
zIndex,
|
|
9
|
+
onLoad,
|
|
10
|
+
onClick,
|
|
11
|
+
clusterer,
|
|
12
|
+
children
|
|
13
|
+
}) => {
|
|
14
|
+
return (
|
|
15
|
+
<MarkerF
|
|
16
|
+
position={position}
|
|
17
|
+
title={title}
|
|
18
|
+
options={{ icon: icon }}
|
|
19
|
+
zIndex={zIndex}
|
|
20
|
+
onLoad={onLoad}
|
|
21
|
+
onClick={onClick}
|
|
22
|
+
clusterer={clusterer}
|
|
23
|
+
>
|
|
24
|
+
{children}
|
|
25
|
+
</MarkerF>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default MapMarker;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
export const eventTypes = {
|
|
2
|
-
FILTER_APPLIED: "filter_applied",
|
|
3
|
-
MAP_MARKER_CLICKED: "map_marker_clicked",
|
|
4
|
-
JOB_LISTING_SELECTED: "job_listing_selected",
|
|
5
|
-
APPLY_NOW_CLICKED: "apply_now_clicked",
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
export const eventTypes = {
|
|
2
|
+
FILTER_APPLIED: "filter_applied",
|
|
3
|
+
MAP_MARKER_CLICKED: "map_marker_clicked",
|
|
4
|
+
JOB_LISTING_SELECTED: "job_listing_selected",
|
|
5
|
+
APPLY_NOW_CLICKED: "apply_now_clicked",
|
|
6
|
+
EASY_APPLY_CLICKED: "easy_apply_clicked",
|
|
7
|
+
VIEW_DETAILS_CLICKED: "view_details_clicked",
|
|
8
|
+
COMMUTE_ORIGIN_ADDED: "commute_origin_added",
|
|
9
|
+
POI_APPLIED: "point_of_interest_applied",
|
|
10
|
+
VIEW_JOBS_AT_Location: "view_jobs_at_location_clicked",
|
|
11
|
+
FAVORITE_SELECTED: "favorite_job_selected",
|
|
12
|
+
LIST_SORTED: "jobs_list_sorted",
|
|
13
|
+
FILTERS_RESET: "filter_reset_button_clicked",
|
|
14
|
+
EXTERNAL_LINK_CLICKED: "external_link_clicked"
|
|
15
|
+
};
|
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
import React, { createContext, useState, useContext, useEffect, useRef, ReactNode } from 'react';
|
|
2
|
-
import { getStorageObject, setStorageObject } from '~/util/localStorageUtil';
|
|
3
|
-
import { Listing } from '~/types/Listings';
|
|
4
|
-
import { LatLng } from '~/types/LatLng';
|
|
5
|
-
interface IMapContext {
|
|
6
|
-
selectedListItem: Listing | null;
|
|
7
|
-
setSelectedListItem: (item: Listing | null) => void;
|
|
8
|
-
location: any | null;
|
|
9
|
-
setLocation: (location: LatLng | null) => void;
|
|
10
|
-
center: LatLng;
|
|
11
|
-
setCenter: (center: LatLng) => void;
|
|
12
|
-
zoom: number;
|
|
13
|
-
setZoom: (zoom: number) => void;
|
|
14
|
-
selectedPlaces: string[];
|
|
15
|
-
setSelectedPlaces: (places: string[]) => void;
|
|
16
|
-
mapInteracted: boolean;
|
|
17
|
-
setMapInteracted: (interacted: boolean) => void;
|
|
18
|
-
userSetZoom: React.MutableRefObject<boolean>;
|
|
19
|
-
firstLoadListItem: any;
|
|
20
|
-
selectItem: (item: Listing, itemLocation: LatLng | null, zoom: number, center: LatLng) => void;
|
|
21
|
-
filterReset: () => void;
|
|
22
|
-
selectLocationEntity: (location: LatLng) => void;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const MapContext = createContext<IMapContext | undefined>(undefined);
|
|
26
|
-
|
|
27
|
-
export const useMap = () => {
|
|
28
|
-
const context = useContext(MapContext);
|
|
29
|
-
if (!context) {
|
|
30
|
-
throw new Error("useMap must be used within a MapProvider");
|
|
31
|
-
}
|
|
32
|
-
return context;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
interface MapProviderProps {
|
|
36
|
-
children: ReactNode;
|
|
37
|
-
resetFilters: boolean;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const MapProvider: React.FC<MapProviderProps> = ({ children, resetFilters }) => {
|
|
41
|
-
const [selectedListItem, setSelectedListItem] = useState<Listing | null>(getStorageObject('selectedListItem'));
|
|
42
|
-
const [location, setLocation] = useState<any>(getStorageObject('location'));
|
|
43
|
-
const [center, setCenter] = useState<LatLng>(getStorageObject("center", { lat: 39.8283, lng: -98.5795 }) || { lat: 39.8283, lng: -98.5795 });
|
|
44
|
-
const [zoom, setZoom] = useState<number>(getStorageObject("zoom", 10) || 10);
|
|
45
|
-
const [selectedPlaces, setSelectedPlaces] = useState<string[]>([]);
|
|
46
|
-
const [mapInteracted, setMapInteracted] = useState<boolean>(false);
|
|
47
|
-
const [firstLoadListItem] = useState<any>(getStorageObject('selectedListItem', { id: "defaultId" }));
|
|
48
|
-
const userSetZoom = useRef<boolean>(true);
|
|
49
|
-
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
setStorageObject("selectedListItem", selectedListItem);
|
|
52
|
-
}, [selectedListItem]);
|
|
53
|
-
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
localStorage.setItem("zoom", zoom.toString());
|
|
56
|
-
}, [zoom]);
|
|
57
|
-
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
if (location == null) {
|
|
60
|
-
localStorage.removeItem("location");
|
|
61
|
-
} else {
|
|
62
|
-
setStorageObject("location", location);
|
|
63
|
-
}
|
|
64
|
-
}, [location]);
|
|
65
|
-
|
|
66
|
-
useEffect(() => {
|
|
67
|
-
setStorageObject("center", center);
|
|
68
|
-
}, [center]);
|
|
69
|
-
|
|
70
|
-
const selectItem = (item: Listing, itemLocation: LatLng | null, zoom: number, center: LatLng) => {
|
|
71
|
-
setSelectedListItem(item);
|
|
72
|
-
if (mapInteracted === false && itemLocation != null) {
|
|
73
|
-
setLocation(itemLocation);
|
|
74
|
-
}
|
|
75
|
-
if (mapInteracted === false || itemLocation != null) {
|
|
76
|
-
setLocation(itemLocation);
|
|
77
|
-
setCenter(center);
|
|
78
|
-
}
|
|
79
|
-
if (mapInteracted === false) {
|
|
80
|
-
setZoom(zoom);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const filterReset = () => {
|
|
85
|
-
setSelectedPlaces([]);
|
|
86
|
-
setSelectedListItem(null);
|
|
87
|
-
setLocation(null);
|
|
88
|
-
setZoom(8);
|
|
89
|
-
setMapInteracted(false);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
if (resetFilters === true) {
|
|
94
|
-
filterReset();
|
|
95
|
-
}
|
|
96
|
-
}, [resetFilters]);
|
|
97
|
-
|
|
98
|
-
const selectLocationEntity = (location: LatLng) => {
|
|
99
|
-
localStorage.removeItem("selectedListItem");
|
|
100
|
-
setTimeout(() => setLocation(location), 200);
|
|
101
|
-
setSelectedListItem(null);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
return (
|
|
105
|
-
<MapContext.Provider
|
|
106
|
-
value={{
|
|
107
|
-
selectedListItem,
|
|
108
|
-
setSelectedListItem,
|
|
109
|
-
location,
|
|
110
|
-
center,
|
|
111
|
-
setCenter,
|
|
112
|
-
zoom,
|
|
113
|
-
setZoom,
|
|
114
|
-
selectItem,
|
|
115
|
-
setSelectedPlaces,
|
|
116
|
-
selectedPlaces,
|
|
117
|
-
selectLocationEntity,
|
|
118
|
-
setLocation,
|
|
119
|
-
setMapInteracted,
|
|
120
|
-
mapInteracted,
|
|
121
|
-
userSetZoom,
|
|
122
|
-
firstLoadListItem,
|
|
123
|
-
filterReset
|
|
124
|
-
}}
|
|
125
|
-
>
|
|
126
|
-
{children}
|
|
127
|
-
</MapContext.Provider>
|
|
128
|
-
);
|
|
129
|
-
};
|
|
1
|
+
import React, { createContext, useState, useContext, useEffect, useRef, ReactNode } from 'react';
|
|
2
|
+
import { getStorageObject, setStorageObject } from '~/util/localStorageUtil';
|
|
3
|
+
import { Listing } from '~/types/Listings';
|
|
4
|
+
import { LatLng } from '~/types/LatLng';
|
|
5
|
+
interface IMapContext {
|
|
6
|
+
selectedListItem: Listing | null;
|
|
7
|
+
setSelectedListItem: (item: Listing | null) => void;
|
|
8
|
+
location: any | null;
|
|
9
|
+
setLocation: (location: LatLng | null) => void;
|
|
10
|
+
center: LatLng;
|
|
11
|
+
setCenter: (center: LatLng) => void;
|
|
12
|
+
zoom: number;
|
|
13
|
+
setZoom: (zoom: number) => void;
|
|
14
|
+
selectedPlaces: string[];
|
|
15
|
+
setSelectedPlaces: (places: string[]) => void;
|
|
16
|
+
mapInteracted: boolean;
|
|
17
|
+
setMapInteracted: (interacted: boolean) => void;
|
|
18
|
+
userSetZoom: React.MutableRefObject<boolean>;
|
|
19
|
+
firstLoadListItem: any;
|
|
20
|
+
selectItem: (item: Listing, itemLocation: LatLng | null, zoom: number, center: LatLng) => void;
|
|
21
|
+
filterReset: () => void;
|
|
22
|
+
selectLocationEntity: (location: LatLng) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const MapContext = createContext<IMapContext | undefined>(undefined);
|
|
26
|
+
|
|
27
|
+
export const useMap = () => {
|
|
28
|
+
const context = useContext(MapContext);
|
|
29
|
+
if (!context) {
|
|
30
|
+
throw new Error("useMap must be used within a MapProvider");
|
|
31
|
+
}
|
|
32
|
+
return context;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
interface MapProviderProps {
|
|
36
|
+
children: ReactNode;
|
|
37
|
+
resetFilters: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const MapProvider: React.FC<MapProviderProps> = ({ children, resetFilters }) => {
|
|
41
|
+
const [selectedListItem, setSelectedListItem] = useState<Listing | null>(getStorageObject('selectedListItem'));
|
|
42
|
+
const [location, setLocation] = useState<any>(getStorageObject('location'));
|
|
43
|
+
const [center, setCenter] = useState<LatLng>(getStorageObject("center", { lat: 39.8283, lng: -98.5795 }) || { lat: 39.8283, lng: -98.5795 });
|
|
44
|
+
const [zoom, setZoom] = useState<number>(getStorageObject("zoom", 10) || 10);
|
|
45
|
+
const [selectedPlaces, setSelectedPlaces] = useState<string[]>([]);
|
|
46
|
+
const [mapInteracted, setMapInteracted] = useState<boolean>(false);
|
|
47
|
+
const [firstLoadListItem] = useState<any>(getStorageObject('selectedListItem', { id: "defaultId" }));
|
|
48
|
+
const userSetZoom = useRef<boolean>(true);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
setStorageObject("selectedListItem", selectedListItem);
|
|
52
|
+
}, [selectedListItem]);
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
localStorage.setItem("zoom", zoom.toString());
|
|
56
|
+
}, [zoom]);
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (location == null) {
|
|
60
|
+
localStorage.removeItem("location");
|
|
61
|
+
} else {
|
|
62
|
+
setStorageObject("location", location);
|
|
63
|
+
}
|
|
64
|
+
}, [location]);
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
setStorageObject("center", center);
|
|
68
|
+
}, [center]);
|
|
69
|
+
|
|
70
|
+
const selectItem = (item: Listing, itemLocation: LatLng | null, zoom: number, center: LatLng) => {
|
|
71
|
+
setSelectedListItem(item);
|
|
72
|
+
if (mapInteracted === false && itemLocation != null) {
|
|
73
|
+
setLocation(itemLocation);
|
|
74
|
+
}
|
|
75
|
+
if (mapInteracted === false || itemLocation != null) {
|
|
76
|
+
setLocation(itemLocation);
|
|
77
|
+
setCenter(center);
|
|
78
|
+
}
|
|
79
|
+
if (mapInteracted === false) {
|
|
80
|
+
setZoom(zoom);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const filterReset = () => {
|
|
85
|
+
setSelectedPlaces([]);
|
|
86
|
+
setSelectedListItem(null);
|
|
87
|
+
setLocation(null);
|
|
88
|
+
setZoom(8);
|
|
89
|
+
setMapInteracted(false);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (resetFilters === true) {
|
|
94
|
+
filterReset();
|
|
95
|
+
}
|
|
96
|
+
}, [resetFilters]);
|
|
97
|
+
|
|
98
|
+
const selectLocationEntity = (location: LatLng) => {
|
|
99
|
+
localStorage.removeItem("selectedListItem");
|
|
100
|
+
setTimeout(() => setLocation(location), 200);
|
|
101
|
+
setSelectedListItem(null);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<MapContext.Provider
|
|
106
|
+
value={{
|
|
107
|
+
selectedListItem,
|
|
108
|
+
setSelectedListItem,
|
|
109
|
+
location,
|
|
110
|
+
center,
|
|
111
|
+
setCenter,
|
|
112
|
+
zoom,
|
|
113
|
+
setZoom,
|
|
114
|
+
selectItem,
|
|
115
|
+
setSelectedPlaces,
|
|
116
|
+
selectedPlaces,
|
|
117
|
+
selectLocationEntity,
|
|
118
|
+
setLocation,
|
|
119
|
+
setMapInteracted,
|
|
120
|
+
mapInteracted,
|
|
121
|
+
userSetZoom,
|
|
122
|
+
firstLoadListItem,
|
|
123
|
+
filterReset
|
|
124
|
+
}}
|
|
125
|
+
>
|
|
126
|
+
{children}
|
|
127
|
+
</MapContext.Provider>
|
|
128
|
+
);
|
|
129
|
+
};
|