Skip to content

Commit

Permalink
fix: clicking a loo after performing a search (#1296)
Browse files Browse the repository at this point in the history
application due to conflict btwn search and loo lat/lng. fx inf loop on search
  • Loading branch information
ob6160 committed Mar 27, 2022
1 parent dc6456a commit e2cb8c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 4 additions & 8 deletions src/components/LooMap/LooMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,6 @@ const LooMap: React.FC<LooMapProps> = ({
setHydratedToilets(loadedLooValues);
}, [loadedToilets, mapState.loadedGroups]);

// Override the map location with the search result if present.
useEffect(() => {
if (mapState?.searchLocation && mapState?.map) {
mapState.map.setView(mapState.searchLocation);
}
}, [mapState.map, mapState.searchLocation]);

// Begin location service initialisation.
const onLocationFound = useCallback(
(event: { latitude: any; longitude: any }) => {
Expand Down Expand Up @@ -186,11 +179,14 @@ const LooMap: React.FC<LooMapProps> = ({
});
}, [mapState.map, isActive, setMapState, startLocate, stopLocate]);

// Override the map location with the search result if present.
useEffect(() => {
if (mapState?.searchLocation && mapState?.map) {
mapState.map.setView(mapState.searchLocation);
}
}, [mapState.map, mapState.searchLocation]);
// Only update the map when the search location changes.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [mapState.searchLocation]);

return (
<Box
Expand Down
6 changes: 5 additions & 1 deletion src/components/LooMap/Markers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,14 @@ const MarkerGroup: React.FC<{
}
)
.on('click', () => {
// Clear the current search upon navigation
setMapState({ searchLocation: undefined });
router.push(`/loos/${toilet.id}`);
})
.on('keydown', (event: { originalEvent: { keyCode: number } }) => {
if (event.originalEvent.keyCode === KEY_ENTER) {
// Clear the current search upon navigation
setMapState({ searchLocation: undefined });
router.push(`/loos/${toilet.id}`);
}
});
Expand All @@ -122,7 +126,7 @@ const MarkerGroup: React.FC<{
marker.getElement()?.setAttribute('aria-label', 'Public Toilet');
return marker;
},
[mapState.focus, router]
[mapState?.focus?.id, router, setMapState]
);

const [appliedFilterTypes, setAppliedFilterTypes] = useState<
Expand Down

0 comments on commit e2cb8c2

Please sign in to comment.