From ef659f5fd22ee220a0a47064ea3c48faa4de35c9 Mon Sep 17 00:00:00 2001 From: Gaya Kessler Date: Wed, 24 Jun 2020 14:21:31 +0200 Subject: [PATCH] prevent auto updating --- src/components/App/useLocationHandler.ts | 2 +- src/components/App/useRouteNavigation.ts | 11 ++++++++++- src/components/ConfigureRun/StartingPoint.tsx | 9 ++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/components/App/useLocationHandler.ts b/src/components/App/useLocationHandler.ts index f7cf320..608ea56 100644 --- a/src/components/App/useLocationHandler.ts +++ b/src/components/App/useLocationHandler.ts @@ -21,7 +21,7 @@ function useLocationHandler(): void { setLocations(newLocations); } } - }, [locations, locationsSearchResults, setLocations]); + }, [locationSearch, locations, locationsSearchResults, setLocations]); } export default useLocationHandler; diff --git a/src/components/App/useRouteNavigation.ts b/src/components/App/useRouteNavigation.ts index 065d91e..8ee2ca1 100644 --- a/src/components/App/useRouteNavigation.ts +++ b/src/components/App/useRouteNavigation.ts @@ -1,5 +1,5 @@ import { useSetRecoilState } from 'recoil'; -import { useCallback, useEffect } from 'react'; +import { useCallback, useEffect, useState } from 'react'; import { routeDistanceState, @@ -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 @@ -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) { diff --git a/src/components/ConfigureRun/StartingPoint.tsx b/src/components/ConfigureRun/StartingPoint.tsx index 317e210..fe975f6 100644 --- a/src/components/ConfigureRun/StartingPoint.tsx +++ b/src/components/ConfigureRun/StartingPoint.tsx @@ -70,7 +70,14 @@ const StartingPoint: React.FC = ({ location, setLocation }) } setLocationSearchState(debouncedLocation); - }, [debouncedLocation, location, locationLabelByKey, setLocationSearchState]); + }, [ + debouncedLocation, + location, + locationInput, + locationLabelByKey, + locationSearch, + setLocationSearchState, + ]); const noOptionsText = locationInput === '' ? 'Start typing to search...' : undefined;