Skip to content

Commit

Permalink
make useEffect sync
Browse files Browse the repository at this point in the history
  • Loading branch information
usavkov-epam committed Dec 14, 2023
1 parent f092328 commit 141edda
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/FindLocation/useLocationsRecords.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);

Expand Down

0 comments on commit 141edda

Please sign in to comment.