Skip to content

Commit

Permalink
prevent auto updating
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaya committed Jun 24, 2020
1 parent a3a37ab commit ef659f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/App/useLocationHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function useLocationHandler(): void {
setLocations(newLocations);
}
}
}, [locations, locationsSearchResults, setLocations]);
}, [locationSearch, locations, locationsSearchResults, setLocations]);
}

export default useLocationHandler;
11 changes: 10 additions & 1 deletion src/components/App/useRouteNavigation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useSetRecoilState } from 'recoil';
import { useCallback, useEffect } from 'react';
import { useCallback, useEffect, useState } from 'react';

import {
routeDistanceState,
Expand Down Expand Up @@ -56,6 +56,7 @@ function useLoadRouteFromQueryParameters(): (search: string) => void {
}

function useRouteNavigation(closeDrawer: () => void): void {
const [initialLoaded, setInitialLoaded] = useState(false);
const loadRouteFromQueryParameters = useLoadRouteFromQueryParameters();

// listen to route changes
Expand All @@ -66,6 +67,14 @@ function useRouteNavigation(closeDrawer: () => void): void {
// load initial route from query params
const hasRoute = hasRouteQueryParameters(window.location.search);

useEffect(() => {
if (hasRoute && !initialLoaded) {
loadRouteFromQueryParameters(window.location.search);
}

setInitialLoaded(true);
}, [hasRoute, initialLoaded, loadRouteFromQueryParameters]);

// initial load
useEffect(() => {
if (hasRoute) {
Expand Down
9 changes: 8 additions & 1 deletion src/components/ConfigureRun/StartingPoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ const StartingPoint: React.FC<StartingPointProps> = ({ location, setLocation })
}

setLocationSearchState(debouncedLocation);
}, [debouncedLocation, location, locationLabelByKey, setLocationSearchState]);
}, [
debouncedLocation,
location,
locationInput,
locationLabelByKey,
locationSearch,
setLocationSearchState,
]);

const noOptionsText = locationInput === '' ? 'Start typing to search...' : undefined;

Expand Down

0 comments on commit ef659f5

Please sign in to comment.