diff --git a/lib/actions/form.js b/lib/actions/form.js index 61ef9b87f..2f0223833 100644 --- a/lib/actions/form.js +++ b/lib/actions/form.js @@ -174,6 +174,10 @@ export function checkShouldReplanTrip(autoPlan, isMobile, oldQuery, newQuery) { } } +const checkIfOriginSetToCurrentPosition = (query, currentPosition) => + query?.from?.lat === currentPosition?.coords?.latitude && + query?.from?.lon === currentPosition?.coords?.longitude + /** * If departArrive is set to 'NOW', update the query time to current */ @@ -198,8 +202,9 @@ export function updateQueryTimeIfLeavingNow() { export function formChanged(oldQuery, newQuery) { return function (dispatch, getState) { const state = getState() - const { config, ui } = state.otp + const { config, location, ui } = state.otp const { autoPlan, debouncePlanTimeMs } = config + const { currentPosition } = location const isMobile = coreUtils.ui.isMobile() const { fromChanged, @@ -209,6 +214,11 @@ export function formChanged(oldQuery, newQuery) { toChanged } = checkShouldReplanTrip(autoPlan, isMobile, oldQuery, newQuery) + const originSetToCurrentPosition = checkIfOriginSetToCurrentPosition( + newQuery, + currentPosition + ) + dispatch(updateQueryTimeIfLeavingNow()) // Only clear the main panel if a single location changed. This prevents @@ -222,11 +232,13 @@ export function formChanged(oldQuery, newQuery) { // location changes. if (fromChanged || toChanged) { dispatch(clearActiveSearch()) - // Return to search screen on mobile only if not currently on welcome - // screen (otherwise when the current position is auto-set the screen - // will change unexpectedly). + // Return to search screen on mobile only if not setting to current location + // (otherwise when the current position is auto-set the screen will change unexpectedly). if ( - ui.mobileScreen !== MobileScreens.WELCOME_SCREEN && + !( + ui.mobileScreen === MobileScreens.WELCOME_SCREEN && + originSetToCurrentPosition + ) && !locationChangedToBlank ) { dispatch(setMobileScreen(MobileScreens.SEARCH_FORM))