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 3 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
20 changes: 17 additions & 3 deletions lib/components/form/batch-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Props = {
modeSettingValues: ModeSettingValues
onPlanTripClick: () => void
routingQuery: any
setQueryParam: (evt: any) => void
setUrlSearch: (evt: any) => void
spacedOutModeSelector?: boolean
updateQueryTimeIfLeavingNow: () => void
Expand Down Expand Up @@ -81,6 +82,7 @@ function BatchSettings({
modeSettingValues,
onPlanTripClick,
routingQuery,
setQueryParam,
setUrlSearch,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need setUrlSearch? Is it used somewhere else? Should we use something else instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daniel-heppner-ibigroup Yeah you can delete setUrlSearch from this file.

spacedOutModeSelector,
updateQueryTimeIfLeavingNow
Expand Down Expand Up @@ -189,6 +191,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 +213,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 @@ -244,7 +257,7 @@ function BatchSettings({
id: 'components.BatchSearchScreen.modeSelectorLabel'
})}
modeButtons={processedModeButtons}
onSettingsUpdate={setUrlSearch}
onSettingsUpdate={_onSettingsUpdate}
onToggleModeButton={_toggleModeButton}
/>
<PlanTripButton
Expand Down Expand Up @@ -298,6 +311,7 @@ const mapStateToProps = (state: any) => {

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