From 141eddadccbb49a67acf1a81a1223592be6184ae Mon Sep 17 00:00:00 2001 From: Yury Saukou Date: Thu, 14 Dec 2023 22:02:50 +0400 Subject: [PATCH] make useEffect sync --- lib/FindLocation/useLocationsRecords.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/FindLocation/useLocationsRecords.js b/lib/FindLocation/useLocationsRecords.js index 73f4686c..86114972 100644 --- a/lib/FindLocation/useLocationsRecords.js +++ b/lib/FindLocation/useLocationsRecords.js @@ -52,32 +52,32 @@ export const useLocationsRecords = ({ selectedLocations, initialSelected, institutionsMap, - campusessMap, + campusesMap, librariesMap, }) => { const eventEmitter = useEventEmitter(); - const [isProcessing, setIsProcessing] = useState(false); + const [isProcessing, setIsProcessing] = useState(true); const [locationRecords, setLocationRecords] = useState([]); const { locations, isLoading: isLocationsLoading } = useLocations({ onSuccess: emitInitialSelectedRecords.bind(null, eventEmitter, initialSelected), }); useEffect(() => { - Promise.resolve(true) - .then(setIsProcessing) - .then(() => hydrateLocations(locations, selectedLocations, institutionsMap, campusessMap, librariesMap)) - .then((items) => filterAndSort(FILTERS_CONFIG, filters, items)) - .then(customFilter) - .then(dehydrateLocations) - .then(setLocationRecords) - .then(() => setIsProcessing(false)); + setIsProcessing(true); + + const hydrated = hydrateLocations(locations, selectedLocations, institutionsMap, campusesMap, librariesMap); + const filtered = customFilter(filterAndSort(FILTERS_CONFIG, filters, hydrated)); + const dehydrated = dehydrateLocations(filtered); + + setLocationRecords(dehydrated); + setIsProcessing(false); }, [ customFilter, filters, locations, selectedLocations, institutionsMap, - campusessMap, + campusesMap, librariesMap, ]);