@abcagency/hc-ui-components 1.3.28 → 1.3.30

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.
Files changed (34) hide show
  1. package/dist/components/containers/accordions/filter-item-container.js +4 -1
  2. package/dist/components/containers/accordions/filter-item-container.js.map +1 -1
  3. package/dist/components/containers/maps/info-window-content-container.js +9 -4
  4. package/dist/components/containers/maps/info-window-content-container.js.map +1 -1
  5. package/dist/components/containers/maps/map-marker-container.js +3 -5
  6. package/dist/components/containers/maps/map-marker-container.js.map +1 -1
  7. package/dist/components/modules/list/field-mapper.js +2 -2
  8. package/dist/components/modules/list/field-mapper.js.map +1 -1
  9. package/dist/components/modules/list/header-item.js +2 -1
  10. package/dist/components/modules/list/header-item.js.map +1 -1
  11. package/dist/components/modules/list/header.js +6 -2
  12. package/dist/components/modules/list/header.js.map +1 -1
  13. package/dist/components/modules/list/item-list.js +46 -19
  14. package/dist/components/modules/list/item-list.js.map +1 -1
  15. package/dist/components/modules/list/list-item/list-item.js +4 -4
  16. package/dist/components/modules/list/list-item/list-item.js.map +1 -1
  17. package/dist/components/modules/maps/info-window-content.js +3 -2
  18. package/dist/components/modules/maps/info-window-content.js.map +1 -1
  19. package/dist/contexts/mapListContext.js +6 -0
  20. package/dist/contexts/mapListContext.js.map +1 -1
  21. package/dist/styles/index.css +1 -1
  22. package/dist/types/components/modules/list/header.d.ts +2 -1
  23. package/dist/types/contexts/mapListContext.d.ts +1 -0
  24. package/package.json +1 -1
  25. package/src/components/containers/accordions/filter-item-container.js +69 -66
  26. package/src/components/containers/maps/info-window-content-container.js +5 -3
  27. package/src/components/containers/maps/map-marker-container.js +2 -2
  28. package/src/components/modules/list/field-mapper.js +4 -3
  29. package/src/components/modules/list/header-item.js +92 -91
  30. package/src/components/modules/list/header.js +51 -49
  31. package/src/components/modules/list/item-list.tsx +93 -59
  32. package/src/components/modules/list/list-item/list-item.js +130 -130
  33. package/src/components/modules/maps/info-window-content.js +36 -35
  34. package/src/contexts/mapListContext.tsx +319 -311
@@ -1,311 +1,319 @@
1
- import React, { createContext, useState, useEffect, useContext, ReactNode } from 'react';
2
-
3
- import { generateFilterOptions, applyFilters, filterListingsByLocation } from '~/util/filterUtil';
4
- import { getStorageObject, setStorageObject } from '~/util/localStorageUtil';
5
- import { updateURLWithFilters, filtersFromURL } from '~/util/urlFilterUtil';
6
-
7
- import { getListingEntities } from "~/services/listingEntityService";
8
- import fetchListings from '~/services/listingAggregatorService';
9
-
10
- import { Listing } from '~/types/Listings';
11
- import { ListingEntity } from '~/types/ListingEntity';
12
- import { Recruiter } from '~/types/Recruiter';
13
- import { MapConfig, MapConfig as SiteConfig } from '~/types/config/MapConfig';
14
-
15
- interface MapListContextProps {
16
- loading: boolean;
17
- allListings: Listing[];
18
- filteredListings: Listing[];
19
- mapItems: any;
20
- query: string | null;
21
- setNewFilteredListings: (filteredListings: Listing[]) => void;
22
- setQuery: (query: string | null) => void;
23
- listingEntities: Record<number, ListingEntity> | null;
24
- selectedFilters: Record<string, any>;
25
- setSelectedFilters: (filters: Record<string, any>) => void;
26
- filterOptions: any;
27
- recruiters: Record<number, Recruiter>;
28
- handleFilterListingsByLocation: (selectedLocation: any) => void;
29
- filterDialogIsOpen: boolean;
30
- setFilterDialogIsOpen: (isOpen: boolean) => void;
31
- setMobileTab: (tab: string) => void;
32
- mobileTab: string;
33
- siteConfig: SiteConfig;
34
- favorites: number[];
35
- handleSettingFavorites: (favorites: number[] | null) => void;
36
- setFilterByFavorites: (filter: boolean) => void;
37
- filterByFavorites: boolean;
38
- commuteLocation: any | null;
39
- setCommuteLocation: (location: any | null) => void;
40
- navigateToDetails: (id: number) => void;
41
- navigateToEasyApply: (id: number) => void;
42
- Link: React.ComponentType<any>;
43
- linkFormat: string;
44
- sortSetting: { field: string; type: string };
45
- setSortSetting: (setting: { field: string; type: string }) => void;
46
- trackEvent: (event: string) => void;
47
- }
48
-
49
- const MapListContext = createContext<MapListContextProps | undefined>(undefined);
50
-
51
- export const useMapList = () => {
52
- const context = useContext(MapListContext);
53
- if (!context) {
54
- throw new Error('useMapList must be used within a MapListProvider');
55
- }
56
- return context;
57
- };
58
-
59
- const getQuery = (): string | null => {
60
- let query: string | null = null;
61
- if (typeof window !== 'undefined') {
62
- query = localStorage.getItem('query');
63
- }
64
- return query;
65
- };
66
-
67
- interface MapListProviderProps {
68
- children: ReactNode;
69
- siteConfig: MapConfig;
70
- resetFilters: boolean;
71
- navigateToDetails: (id: number) => void;
72
- navigateToEasyApply: (id: number) => void;
73
- Link: React.ComponentType<any>;
74
- linkFormat: string;
75
- trackEvent: (event: string) => void;
76
- listings?: Listing[];
77
- setFiltersUrl?:boolean;
78
- }
79
-
80
- export const MapListProvider: React.FC<MapListProviderProps> = ({
81
- children,
82
- siteConfig,
83
- resetFilters,
84
- navigateToDetails,
85
- navigateToEasyApply,
86
- Link,
87
- linkFormat,
88
- trackEvent,
89
- listings = [],
90
- setFiltersUrl
91
- }) => {
92
- const firstLoadFilters = () =>{
93
- let urlFilters = filtersFromURL(window.location)?.filters;
94
- return (setFiltersUrl === true && urlFilters && Object.keys(urlFilters).length > 0) ? urlFilters : getStorageObject('selectedFilters', {}) || {}
95
- }
96
- const [allListings, setAllListings] = useState<Listing[]>(getStorageObject("listings", listings) || []);
97
- const [filteredListings, setFilteredListings] = useState<Listing[]>([]);
98
- const [loading, setLoading] = useState<boolean>(false);
99
- const [mapItems, setMapItems] = useState<any>(getStorageObject('mapItems', []) || []);
100
- const [query, setQuery] = useState<string | null>(() => resetFilters ? null : getQuery());
101
- const [sortSetting, setSortSetting] = useState<{ field: string; type: string }>(getStorageObject('sortSetting', { field: 'position', type: 'asc' }) || { field: 'position', type: 'asc' });
102
- const [listingEntities, setListingEntities] = useState<Record<number, ListingEntity> | null>(getStorageObject("listingEntities", null));
103
- const [firstLoad, setFirstLoad] = useState<boolean>(true);
104
- const [commuteLocation, setCommuteLocation] = useState<any | null>(getStorageObject('commuteLocation'));
105
- const [selectedFilters, setSelectedFilters] = useState<Record<string, any>>(() => resetFilters ? {} : firstLoadFilters());
106
- const [filterOptions, setFilterOptions] = useState<any>();
107
- const [recruiters, setRecruiters] = useState<Record<number, Recruiter>>(getStorageObject("recruiters", {}) || {});
108
- const [filterDialogIsOpen, setFilterDialogIsOpen] = useState<boolean>(false);
109
- const [mobileTab, setMobileTab] = useState<string>("listTab");
110
- const [favorites, setFavorites] = useState<number[]>([]);
111
- const [filterByFavorites, setFilterByFavorites] = useState<boolean>(false);
112
-
113
- const setNewFilteredListings = (filteredListings: Listing[]) => {
114
- setFilteredListings(filteredListings);
115
- };
116
-
117
-
118
-
119
- useEffect(() => {
120
- if (!sortSetting) return;
121
- localStorage.setItem('sortSetting', JSON.stringify(sortSetting));
122
- setNewFilteredListings(filteredListings);
123
- }, [sortSetting]);
124
-
125
- useEffect(() => {
126
- const loadedFavorites = JSON.parse(localStorage.getItem('favorites') || '[]');
127
- setFavorites(loadedFavorites);
128
- }, []);
129
-
130
- useEffect(() => {
131
- setStorageObject("commuteLocation", commuteLocation);
132
- }, [commuteLocation]);
133
-
134
- useEffect(() => {
135
- if (!commuteLocation) return;
136
-
137
- async function fetchEntities() {
138
- const distinctEntityIds = [
139
- ...new Set(allListings.map(listing => listing.entityId ?? -1))
140
- ];
141
- try {
142
- const fetchedEntities = await getListingEntities(
143
- distinctEntityIds,
144
- `${commuteLocation.lat}, ${commuteLocation.lng}`
145
- );
146
- setListingEntities(fetchedEntities);
147
- const newFilteredListings: Listing[] = [...filteredListings] ?? [];
148
- for (let i = 0; i < allListings.length; i++) {
149
- const listing = newFilteredListings[i];
150
- if (
151
- listing &&
152
- listing.fields &&
153
- listing.entityId !== undefined &&
154
- listing.entityId !== -1
155
- ) {
156
- const entityId = listing.entityId;
157
- const travelTime = fetchedEntities[entityId]?.travelTime;
158
-
159
- if (travelTime !== undefined && listing.fields) {
160
- listing.fields.travelTime = travelTime;
161
- }
162
- }
163
- }
164
- } catch (error) {
165
- console.error("Failed to fetch listing entities:", error);
166
- }
167
- }
168
-
169
- fetchEntities();
170
- }, [commuteLocation, allListings, siteConfig.companyId]);
171
-
172
- useEffect(() => {
173
- const handleFetchListings = async () => {
174
- if (!getStorageObject('listings') ?? [].length) {
175
- setLoading(true);
176
- }
177
-
178
- try {
179
- const {
180
- listingsResult,
181
- fetchedRecruiters,
182
- fetchedEntities,
183
- distinctItems
184
- } = await fetchListings(query ?? '', siteConfig, commuteLocation);
185
- setAllListings(listingsResult);
186
- setRecruiters(fetchedRecruiters);
187
- setListingEntities(fetchedEntities);
188
- setMapItems(distinctItems);
189
- setStorageObject("mapItems", distinctItems);
190
- setStorageObject("listingEntities", fetchedEntities);
191
- setStorageObject("recruiters", fetchedRecruiters);
192
- setStorageObject("listings", listingsResult);
193
- } catch (error) {
194
- console.log(error);
195
- }
196
- setLoading(false);
197
- };
198
- handleFetchListings();
199
- }, [query, siteConfig]);
200
-
201
- useEffect(() => {
202
- const processListings = () => {
203
- let filteredListings: Listing[];
204
- let tempSelectedFilters = selectedFilters;
205
- let tempQuery = query;
206
-
207
- const { mapItems, filteredListings: tempFilteredListings } = applyFilters(
208
- allListings,
209
- tempSelectedFilters,
210
- tempQuery,
211
- listingEntities,
212
- favorites,
213
- siteConfig
214
- );
215
- filteredListings = tempFilteredListings;
216
-
217
- if (filterByFavorites) {
218
- filteredListings = filteredListings.filter((x: Listing) => favorites.includes(x.id));
219
- }
220
- setNewFilteredListings(filteredListings);
221
- if (firstLoad && tempSelectedFilters) {
222
- // Update URL with filters if needed
223
- } else if (Object.keys(tempSelectedFilters).length === 0 && !firstLoad) {
224
- localStorage.removeItem('selectedFilters');
225
- } else if (!firstLoad) {
226
- setStorageObject('selectedFilters', tempSelectedFilters);
227
- }
228
- if(setFiltersUrl === true)
229
- {
230
- updateURLWithFilters(tempSelectedFilters, window.location, tempQuery);
231
- }
232
- tempQuery != null ? localStorage.setItem('query', tempQuery) : localStorage.removeItem('query');
233
- setMapItems(mapItems);
234
-
235
- if (tempSelectedFilters) {
236
- const keys = Object.keys(tempSelectedFilters);
237
- const lastKey = keys[keys.length - 1];
238
- const options = generateFilterOptions(
239
- firstLoad ? allListings : filteredListings,
240
- allListings,
241
- siteConfig,
242
- filterOptions,
243
- lastKey,
244
- favorites
245
- );
246
- if (options) {
247
- setFilterOptions(options);
248
- if (firstLoad) setFirstLoad(false);
249
- }
250
- }
251
- };
252
-
253
- processListings();
254
- }, [selectedFilters, query, listingEntities, filterByFavorites, favorites]);
255
-
256
- const handleFilterListingsByLocation = (selectedLocation: any) => {
257
- const { filteredListings } = filterListingsByLocation(
258
- allListings,
259
- selectedLocation,
260
- listingEntities
261
- );
262
- setNewFilteredListings(filteredListings);
263
- };
264
-
265
- const handleSettingFavorites = (newFavorites: number[] | null) => {
266
- if (newFavorites == null) {
267
- localStorage.removeItem('favorites');
268
- } else {
269
- setFavorites(newFavorites);
270
- localStorage.setItem('favorites', JSON.stringify(newFavorites));
271
- }
272
- };
273
-
274
- return (
275
- <MapListContext.Provider value={{
276
- loading,
277
- allListings,
278
- filteredListings,
279
- mapItems,
280
- query,
281
- setNewFilteredListings,
282
- setQuery,
283
- listingEntities,
284
- selectedFilters,
285
- setSelectedFilters,
286
- filterOptions,
287
- recruiters,
288
- handleFilterListingsByLocation,
289
- filterDialogIsOpen,
290
- setFilterDialogIsOpen,
291
- setMobileTab,
292
- mobileTab,
293
- siteConfig,
294
- favorites,
295
- handleSettingFavorites,
296
- setFilterByFavorites,
297
- filterByFavorites,
298
- commuteLocation,
299
- setCommuteLocation,
300
- navigateToDetails,
301
- navigateToEasyApply,
302
- Link,
303
- linkFormat,
304
- sortSetting,
305
- setSortSetting,
306
- trackEvent
307
- }}>
308
- {children}
309
- </MapListContext.Provider>
310
- );
311
- };
1
+ import React, { createContext, useState, useEffect, useContext, ReactNode } from 'react';
2
+
3
+ import { generateFilterOptions, applyFilters, filterListingsByLocation } from '~/util/filterUtil';
4
+ import { getStorageObject, setStorageObject } from '~/util/localStorageUtil';
5
+ import { updateURLWithFilters, filtersFromURL } from '~/util/urlFilterUtil';
6
+
7
+ import { getListingEntities } from "~/services/listingEntityService";
8
+ import fetchListings from '~/services/listingAggregatorService';
9
+
10
+ import { Listing } from '~/types/Listings';
11
+ import { ListingEntity } from '~/types/ListingEntity';
12
+ import { Recruiter } from '~/types/Recruiter';
13
+ import { MapConfig, MapConfig as SiteConfig } from '~/types/config/MapConfig';
14
+
15
+ interface MapListContextProps {
16
+ loading: boolean;
17
+ allListings: Listing[];
18
+ filteredListings: Listing[];
19
+ mapItems: any;
20
+ query: string | null;
21
+ setNewFilteredListings: (filteredListings: Listing[]) => void;
22
+ setQuery: (query: string | null) => void;
23
+ listingEntities: Record<number, ListingEntity> | null;
24
+ selectedFilters: Record<string, any>;
25
+ setSelectedFilters: (filters: Record<string, any>) => void;
26
+ filterOptions: any;
27
+ recruiters: Record<number, Recruiter>;
28
+ handleFilterListingsByLocation: (selectedLocation: any) => void;
29
+ filterDialogIsOpen: boolean;
30
+ setFilterDialogIsOpen: (isOpen: boolean) => void;
31
+ setMobileTab: (tab: string) => void;
32
+ mobileTab: string;
33
+ siteConfig: SiteConfig;
34
+ favorites: number[];
35
+ resetEntityFilter: () => void;
36
+ handleSettingFavorites: (favorites: number[] | null) => void;
37
+ setFilterByFavorites: (filter: boolean) => void;
38
+ filterByFavorites: boolean;
39
+ commuteLocation: any | null;
40
+ setCommuteLocation: (location: any | null) => void;
41
+ navigateToDetails: (id: number) => void;
42
+ navigateToEasyApply: (id: number) => void;
43
+ Link: React.ComponentType<any>;
44
+ linkFormat: string;
45
+ sortSetting: { field: string; type: string };
46
+ setSortSetting: (setting: { field: string; type: string }) => void;
47
+ trackEvent: (event: string) => void;
48
+ }
49
+
50
+ const MapListContext = createContext<MapListContextProps | undefined>(undefined);
51
+
52
+ export const useMapList = () => {
53
+ const context = useContext(MapListContext);
54
+ if (!context) {
55
+ throw new Error('useMapList must be used within a MapListProvider');
56
+ }
57
+ return context;
58
+ };
59
+
60
+ const getQuery = (): string | null => {
61
+ let query: string | null = null;
62
+ if (typeof window !== 'undefined') {
63
+ query = localStorage.getItem('query');
64
+ }
65
+ return query;
66
+ };
67
+
68
+ interface MapListProviderProps {
69
+ children: ReactNode;
70
+ siteConfig: MapConfig;
71
+ resetFilters: boolean;
72
+ navigateToDetails: (id: number) => void;
73
+ navigateToEasyApply: (id: number) => void;
74
+ Link: React.ComponentType<any>;
75
+ linkFormat: string;
76
+ trackEvent: (event: string) => void;
77
+ listings?: Listing[];
78
+ setFiltersUrl?:boolean;
79
+ }
80
+
81
+ export const MapListProvider: React.FC<MapListProviderProps> = ({
82
+ children,
83
+ siteConfig,
84
+ resetFilters,
85
+ navigateToDetails,
86
+ navigateToEasyApply,
87
+ Link,
88
+ linkFormat,
89
+ trackEvent,
90
+ listings = [],
91
+ setFiltersUrl
92
+ }) => {
93
+ const firstLoadFilters = () =>{
94
+ let urlFilters = filtersFromURL(window.location)?.filters;
95
+ return (setFiltersUrl === true && urlFilters && Object.keys(urlFilters).length > 0) ? urlFilters : getStorageObject('selectedFilters', {}) || {}
96
+ }
97
+ const [allListings, setAllListings] = useState<Listing[]>(getStorageObject("listings", listings) || []);
98
+ const [filteredListings, setFilteredListings] = useState<Listing[]>([]);
99
+ const [loading, setLoading] = useState<boolean>(false);
100
+ const [mapItems, setMapItems] = useState<any>(getStorageObject('mapItems', []) || []);
101
+ const [query, setQuery] = useState<string | null>(() => resetFilters ? null : getQuery());
102
+ const [sortSetting, setSortSetting] = useState<{ field: string; type: string }>(getStorageObject('sortSetting', { field: 'position', type: 'asc' }) || { field: 'position', type: 'asc' });
103
+ const [listingEntities, setListingEntities] = useState<Record<number, ListingEntity> | null>(getStorageObject("listingEntities", null));
104
+ const [firstLoad, setFirstLoad] = useState<boolean>(true);
105
+ const [commuteLocation, setCommuteLocation] = useState<any | null>(getStorageObject('commuteLocation'));
106
+ const [selectedFilters, setSelectedFilters] = useState<Record<string, any>>(() => resetFilters ? {} : firstLoadFilters());
107
+ const [filterOptions, setFilterOptions] = useState<any>();
108
+ const [recruiters, setRecruiters] = useState<Record<number, Recruiter>>(getStorageObject("recruiters", {}) || {});
109
+ const [filterDialogIsOpen, setFilterDialogIsOpen] = useState<boolean>(false);
110
+ const [mobileTab, setMobileTab] = useState<string>("listTab");
111
+ const [favorites, setFavorites] = useState<number[]>([]);
112
+ const [filterByFavorites, setFilterByFavorites] = useState<boolean>(false);
113
+
114
+ const setNewFilteredListings = (filteredListings: Listing[]) => {
115
+ setFilteredListings(filteredListings);
116
+ };
117
+
118
+
119
+
120
+ useEffect(() => {
121
+ if (!sortSetting) return;
122
+ localStorage.setItem('sortSetting', JSON.stringify(sortSetting));
123
+ setNewFilteredListings(filteredListings);
124
+ }, [sortSetting]);
125
+
126
+ useEffect(() => {
127
+ const loadedFavorites = JSON.parse(localStorage.getItem('favorites') || '[]');
128
+ setFavorites(loadedFavorites);
129
+ }, []);
130
+
131
+ useEffect(() => {
132
+ setStorageObject("commuteLocation", commuteLocation);
133
+ }, [commuteLocation]);
134
+
135
+ useEffect(() => {
136
+ if (!commuteLocation) return;
137
+
138
+ async function fetchEntities() {
139
+ const distinctEntityIds = [
140
+ ...new Set(allListings.map(listing => listing.entityId ?? -1))
141
+ ];
142
+ try {
143
+ const fetchedEntities = await getListingEntities(
144
+ distinctEntityIds,
145
+ `${commuteLocation.lat}, ${commuteLocation.lng}`
146
+ );
147
+ setListingEntities(fetchedEntities);
148
+ const newFilteredListings: Listing[] = [...filteredListings] ?? [];
149
+ for (let i = 0; i < allListings.length; i++) {
150
+ const listing = newFilteredListings[i];
151
+ if (
152
+ listing &&
153
+ listing.fields &&
154
+ listing.entityId !== undefined &&
155
+ listing.entityId !== -1
156
+ ) {
157
+ const entityId = listing.entityId;
158
+ const travelTime = fetchedEntities[entityId]?.travelTime;
159
+
160
+ if (travelTime !== undefined && listing.fields) {
161
+ listing.fields.travelTime = travelTime;
162
+ }
163
+ }
164
+ }
165
+ } catch (error) {
166
+ console.error("Failed to fetch listing entities:", error);
167
+ }
168
+ }
169
+
170
+ fetchEntities();
171
+ }, [commuteLocation, allListings, siteConfig.companyId]);
172
+
173
+ useEffect(() => {
174
+ const handleFetchListings = async () => {
175
+ if (!getStorageObject('listings') ?? [].length) {
176
+ setLoading(true);
177
+ }
178
+
179
+ try {
180
+ const {
181
+ listingsResult,
182
+ fetchedRecruiters,
183
+ fetchedEntities,
184
+ distinctItems
185
+ } = await fetchListings(query ?? '', siteConfig, commuteLocation);
186
+ setAllListings(listingsResult);
187
+ setRecruiters(fetchedRecruiters);
188
+ setListingEntities(fetchedEntities);
189
+ setMapItems(distinctItems);
190
+ setStorageObject("mapItems", distinctItems);
191
+ setStorageObject("listingEntities", fetchedEntities);
192
+ setStorageObject("recruiters", fetchedRecruiters);
193
+ setStorageObject("listings", listingsResult);
194
+ } catch (error) {
195
+ console.log(error);
196
+ }
197
+ setLoading(false);
198
+ };
199
+ handleFetchListings();
200
+ }, [query, siteConfig]);
201
+
202
+ useEffect(() => {
203
+ const processListings = () => {
204
+ let filteredListings: Listing[];
205
+ let tempSelectedFilters = selectedFilters;
206
+ let tempQuery = query;
207
+
208
+ const { mapItems, filteredListings: tempFilteredListings } = applyFilters(
209
+ allListings,
210
+ tempSelectedFilters,
211
+ tempQuery,
212
+ listingEntities,
213
+ favorites,
214
+ siteConfig
215
+ );
216
+ filteredListings = tempFilteredListings;
217
+
218
+ if (filterByFavorites) {
219
+ filteredListings = filteredListings.filter((x: Listing) => favorites.includes(x.id));
220
+ }
221
+ setNewFilteredListings(filteredListings);
222
+ if (firstLoad && tempSelectedFilters) {
223
+ // Update URL with filters if needed
224
+ } else if (Object.keys(tempSelectedFilters).length === 0 && !firstLoad) {
225
+ localStorage.removeItem('selectedFilters');
226
+ } else if (!firstLoad) {
227
+ setStorageObject('selectedFilters', tempSelectedFilters);
228
+ }
229
+ if(setFiltersUrl === true)
230
+ {
231
+ updateURLWithFilters(tempSelectedFilters, window.location, tempQuery);
232
+ }
233
+ tempQuery != null ? localStorage.setItem('query', tempQuery) : localStorage.removeItem('query');
234
+ setMapItems(mapItems);
235
+
236
+ if (tempSelectedFilters) {
237
+ const keys = Object.keys(tempSelectedFilters);
238
+ const lastKey = keys[keys.length - 1];
239
+ const options = generateFilterOptions(
240
+ firstLoad ? allListings : filteredListings,
241
+ allListings,
242
+ siteConfig,
243
+ filterOptions,
244
+ lastKey,
245
+ favorites
246
+ );
247
+ if (options) {
248
+ setFilterOptions(options);
249
+ if (firstLoad) setFirstLoad(false);
250
+ }
251
+ }
252
+ };
253
+
254
+ processListings();
255
+ }, [selectedFilters, query, listingEntities, filterByFavorites, favorites]);
256
+
257
+ const handleFilterListingsByLocation = (selectedLocation: any) => {
258
+ const { filteredListings } = filterListingsByLocation(
259
+ allListings,
260
+ selectedLocation,
261
+ listingEntities
262
+ );
263
+ setNewFilteredListings(filteredListings);
264
+ };
265
+
266
+ const resetEntityFilter = () => {
267
+ let newFilters = {...selectedFilters};
268
+ delete newFilters.entityId;
269
+ setSelectedFilters(newFilters);
270
+ }
271
+
272
+ const handleSettingFavorites = (newFavorites: number[] | null) => {
273
+ if (newFavorites == null) {
274
+ localStorage.removeItem('favorites');
275
+ } else {
276
+ setFavorites(newFavorites);
277
+ localStorage.setItem('favorites', JSON.stringify(newFavorites));
278
+ }
279
+ };
280
+
281
+ return (
282
+ <MapListContext.Provider value={{
283
+ loading,
284
+ allListings,
285
+ filteredListings,
286
+ mapItems,
287
+ query,
288
+ setNewFilteredListings,
289
+ setQuery,
290
+ listingEntities,
291
+ selectedFilters,
292
+ setSelectedFilters,
293
+ filterOptions,
294
+ recruiters,
295
+ handleFilterListingsByLocation,
296
+ filterDialogIsOpen,
297
+ setFilterDialogIsOpen,
298
+ setMobileTab,
299
+ mobileTab,
300
+ siteConfig,
301
+ favorites,
302
+ handleSettingFavorites,
303
+ resetEntityFilter,
304
+ setFilterByFavorites,
305
+ filterByFavorites,
306
+ commuteLocation,
307
+ setCommuteLocation,
308
+ navigateToDetails,
309
+ navigateToEasyApply,
310
+ Link,
311
+ linkFormat,
312
+ sortSetting,
313
+ setSortSetting,
314
+ trackEvent
315
+ }}>
316
+ {children}
317
+ </MapListContext.Provider>
318
+ );
319
+ };