Skip to content

Commit

Permalink
Directions: Update route on autocomplete item click
Browse files Browse the repository at this point in the history
  • Loading branch information
jvaclavik committed Nov 30, 2024
1 parent 3027ef2 commit 73ebbc6
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/components/Directions/DirectionsAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,22 @@ export const DirectionsAutocomplete = ({
};
}, [ALPHABETICAL_MARKER, value]);

const handleUpdate = (coordsOption: Option) => {
if (pointIndex === 0) {
submitFactory(coordsOption, to, mode);
}
if (pointIndex === 1) {
submitFactory(from, coordsOption, mode);
}
};

const submitFactory = useGetOnSubmitFactory(setResult, setLoading);
const onDragEnd = () => {
const lngLat = markerRef.current?.getLngLat();
if (lngLat) {
const coordsOption = getCoordsOption([lngLat.lng, lngLat.lat]);
setValue(coordsOption);

if (pointIndex === 0) {
submitFactory(coordsOption, to, mode);
}
if (pointIndex === 1) {
submitFactory(from, coordsOption, mode);
}
handleUpdate(coordsOption);
}
};

Expand All @@ -278,6 +281,7 @@ export const DirectionsAutocomplete = ({
setInputValue(getOptionLabel(option));
setValue(option);
selectedOptionInputValue.current = getOptionLabel(option);
handleUpdate(option);
};

const { onInputFocus, onInputBlur } = useInputMapClickOverride(
Expand Down

0 comments on commit 73ebbc6

Please sign in to comment.