Skip to content

Commit

Permalink
Directions: Update route on map click (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvaclavik authored Nov 30, 2024
1 parent 7944e04 commit 3bf233a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/components/Directions/DirectionsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,26 @@ const useGlobalMapClickOverride = (
setFrom: (value: Option) => void,
setTo: (value: Option) => void,
) => {
const { mapClickOverrideRef } = useMapStateContext();
const { setResult, setLoading, to, mode } = useDirectionsContext();
const submitFactory = useGetOnSubmitFactory(setResult, setLoading);

const { mapClickOverrideRef } = useMapStateContext();
useEffect(() => {
mapClickOverrideRef.current = (coords, label) => {
const coordinates = getCoordsOption(coords, label);
if (!from) {
setFrom(getCoordsOption(coords, label));
submitFactory(coordinates, to, mode);
setFrom(coordinates);
} else {
setTo(getCoordsOption(coords, label));
submitFactory(from, coordinates, mode);
setTo(coordinates);
}
};

return () => {
mapClickOverrideRef.current = undefined;
};
}, [from, mapClickOverrideRef, setFrom, setTo]);
}, [from, mapClickOverrideRef, mode, setFrom, setTo, submitFactory, to]);
};

export const DirectionsForm = ({ setResult, hideForm }: Props) => {
Expand Down

0 comments on commit 3bf233a

Please sign in to comment.