Skip to content

Commit

Permalink
Merge pull request #1334 from opentripplanner/mobile-screen-when-orig…
Browse files Browse the repository at this point in the history
…in-changes

Update mobile screen when origin changes
  • Loading branch information
amy-corson-ibigroup authored Jan 7, 2025
2 parents abd4067 + e7ffebb commit 5aa70d2
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/actions/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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))
Expand Down

0 comments on commit 5aa70d2

Please sign in to comment.