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

fix: mode selector settings sync with url correctly #1202

Merged
merged 5 commits into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading