Skip to content

Commit

Permalink
fix: fix geolocation not setting selected feature
Browse files Browse the repository at this point in the history
  • Loading branch information
adriansberg committed Nov 12, 2023
1 parent 0ac101b commit 601d226
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/components/search/geolocation-button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ type GeolocationButtonProps = {
};
function GeolocationButton({ onGeolocate, className }: GeolocationButtonProps) {
const { t } = useTranslation();
const { getPosition, isLoading, isUnavailable } = useGeolocation(onGeolocate);
const { getPosition, isLoading, isUnavailable, error } =
useGeolocation(onGeolocate);

if (isUnavailable) return null;

Expand Down Expand Up @@ -43,6 +44,7 @@ function useGeolocation(onSuccess: (feature: GeocoderFeature) => void) {

const getPosition = () => {
setIsLoading(true);
setError(null);

navigator.geolocation.getCurrentPosition(
async (position) => {
Expand All @@ -53,8 +55,8 @@ function useGeolocation(onSuccess: (feature: GeocoderFeature) => void) {
setIsLoading(false);
},
(error) => {
setIsLoading(false);
setError(error);
setIsLoading(false);
},
{ enableHighAccuracy: true, timeout: 10000 },
);
Expand Down
14 changes: 1 addition & 13 deletions src/page-modules/assistant/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,6 @@ function AssistantLayout({
setIsSearching(false);
};

const onGeolocate = (geolocationFeature: GeocoderFeature) => {
if (!selectedToFeature) return;
const query = createTripQuery(
geolocationFeature,
selectedToFeature,
searchTime,
transportModeFilter,
);
setSelectedFromFeature(geolocationFeature);
router.push({ pathname: '/assistant', query });
};

const onSubmitHandler: FormEventHandler<HTMLFormElement> = async (e) => {
e.preventDefault();
if (!selectedFromFeature || !selectedToFeature) return;
Expand Down Expand Up @@ -126,7 +114,7 @@ function AssistantLayout({
button={
<GeolocationButton
className={style.searchInputButton}
onGeolocate={onGeolocate}
onGeolocate={setSelectedFromFeature}
/>
}
/>
Expand Down
1 change: 1 addition & 0 deletions src/page-modules/departures/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function DeparturesLayout({

<Search
label={t(PageText.Departures.search.input.from)}
selectedItem={selectedFeature}
onChange={setSelectedFeature}
button={
<GeolocationButton
Expand Down

0 comments on commit 601d226

Please sign in to comment.