Skip to content

Commit

Permalink
fix(useCoordinateInfo): do not use loading state in hook where it is …
Browse files Browse the repository at this point in the history
…used
  • Loading branch information
simonseyock committed Jun 13, 2024
1 parent a7d1b0c commit 685bcd5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Hooks/useCoordinateInfo/useCoordinateInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ export const useCoordinateInfo = ({
return queryLayers.includes(layerCandidate);
}, [queryLayers]);

useEffect(() => {
if (map && loading) {
map.getTargetElement().style.cursor = 'wait';
return () => {
map.getTargetElement().style.cursor = 'auto';
};
}
return undefined;
}, [loading, map]);

const onMapClick = useCallback(async (olEvt: OlMapBrowserEvent<MouseEvent>) => {
if (_isNil(map)) {
return;
Expand All @@ -94,7 +104,6 @@ export const useCoordinateInfo = ({
.filter(l => isWfsLayer(l)) as WfsLayer[];

setLoading(true);
map.getTargetElement().style.cursor = 'wait';

try {
const results: FeatureLayerResult[] = [];
Expand Down Expand Up @@ -168,19 +177,18 @@ export const useCoordinateInfo = ({
// keep all feature properties (in particular the id) intact.
onSuccess?.({
clickCoordinate: _cloneDeep(coordinate),
loading,
loading: false,
features: _cloneDeep(results)
});

} catch (error: any) {
Logger.error(error);
onError?.(error);
}
map.getTargetElement().style.cursor = '';
setLoading(false);

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [drillDown, featureCount, fetchOpts, infoFormat, layerFilter, loading, map]);
}, [drillDown, featureCount, fetchOpts, infoFormat, layerFilter, map]);

useEffect(() => {
map?.on('click', onMapClick);
Expand Down

0 comments on commit 685bcd5

Please sign in to comment.