Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent mobile view change on location clear #1085

Merged
merged 14 commits into from
Dec 15, 2023
Merged
17 changes: 14 additions & 3 deletions lib/actions/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export function checkShouldReplanTrip(autoPlan, isMobile, oldQuery, newQuery) {
(fromChanged && !toChanged) || (!fromChanged && toChanged)
// Check whether a trip should be auto-replanned
const strategy = (isMobile && autoPlan?.mobile) || autoPlan?.default
const locationChangedToBlank =
(oldQuery.from && !newQuery.from) || (oldQuery.to && !newQuery.to)
const shouldReplanTrip =
evaluateAutoPlanStrategy(
strategy,
Expand All @@ -170,6 +172,7 @@ export function checkShouldReplanTrip(autoPlan, isMobile, oldQuery, newQuery) {
(oldQuery.from || oldQuery.to)
return {
fromChanged,
locationChangedToBlank,
oneLocationChanged,
shouldReplanTrip,
toChanged
Expand Down Expand Up @@ -203,8 +206,13 @@ export function formChanged(oldQuery, newQuery) {
const { config, ui } = state.otp
const { autoPlan, debouncePlanTimeMs } = config
const isMobile = coreUtils.ui.isMobile()
const { fromChanged, oneLocationChanged, shouldReplanTrip, toChanged } =
checkShouldReplanTrip(autoPlan, isMobile, oldQuery, newQuery)
const {
fromChanged,
locationChangedToBlank,
oneLocationChanged,
shouldReplanTrip,
toChanged
} = checkShouldReplanTrip(autoPlan, isMobile, oldQuery, newQuery)

dispatch(updateQueryTimeIfLeavingNow())

Expand All @@ -222,7 +230,10 @@ export function formChanged(oldQuery, newQuery) {
// 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).
if (ui.mobileScreen !== MobileScreens.WELCOME_SCREEN) {
if (
ui.mobileScreen !== MobileScreens.WELCOME_SCREEN &&
!locationChangedToBlank
) {
dispatch(setMobileScreen(MobileScreens.SEARCH_FORM))
}
}
Expand Down
Loading