Skip to content

Commit

Permalink
Merge pull request #1202 from opentripplanner/fix-mode-selector-sync-bug
Browse files Browse the repository at this point in the history
fix: mode selector settings sync with url correctly
  • Loading branch information
daniel-heppner-ibigroup authored Apr 30, 2024
2 parents e484762 + 0462123 commit af8be49
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/components/form/batch-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Props = {
modeSettingValues: ModeSettingValues
onPlanTripClick: () => void
routingQuery: any
setUrlSearch: (evt: any) => void
setQueryParam: (evt: any) => void
spacedOutModeSelector?: boolean
updateQueryTimeIfLeavingNow: () => void
}
Expand Down Expand Up @@ -81,7 +81,7 @@ function BatchSettings({
modeSettingValues,
onPlanTripClick,
routingQuery,
setUrlSearch,
setQueryParam,
spacedOutModeSelector,
updateQueryTimeIfLeavingNow
}: Props) {
Expand Down Expand Up @@ -189,6 +189,17 @@ function BatchSettings({
updateQueryTimeIfLeavingNow
])

/**
* Stores parameters in both the Redux `currentQuery` and URL
* @param params Params to store
*/
const _onSettingsUpdate = useCallback(
(params: any) => {
setQueryParam({ queryParamData: params, ...params })
},
[setQueryParam]
)

const _toggleModeButton = useCallback(
(buttonId: string, newState: boolean) => {
let newButtons
Expand All @@ -200,11 +211,11 @@ function BatchSettings({

// encodeQueryParams serializes the mode buttons for the URL
// to get nice looking URL params and consistency
setUrlSearch(
_onSettingsUpdate(
encodeQueryParams(queryParamConfig, { modeButtons: newButtons })
)
},
[enabledModeButtons, setUrlSearch]
[enabledModeButtons, _onSettingsUpdate]
)

/**
Expand Down Expand Up @@ -242,7 +253,7 @@ function BatchSettings({
id: 'components.BatchSearchScreen.modeSelectorLabel'
})}
modeButtons={processedModeButtons}
onSettingsUpdate={setUrlSearch}
onSettingsUpdate={_onSettingsUpdate}
onToggleModeButton={_toggleModeButton}
/>
<PlanTripButton
Expand Down Expand Up @@ -296,7 +307,7 @@ const mapStateToProps = (state: any) => {

const mapDispatchToProps = {
routingQuery: apiActions.routingQuery,
setUrlSearch: apiActions.setUrlSearch,
setQueryParam: formActions.setQueryParam,
updateQueryTimeIfLeavingNow: formActions.updateQueryTimeIfLeavingNow
}

Expand Down

0 comments on commit af8be49

Please sign in to comment.