Skip to content

Commit 6ecb299

Browse files
committed
refactor(routerId): add confirm message to notify user about alt router
1 parent 3f68af9 commit 6ecb299

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

Diff for: lib/actions/ui.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,17 @@ export function matchContentToUrl (location) {
7777
// Update map location/zoom and optionally override router ID.
7878
dispatch(setMapCenter({ lat, lon }))
7979
dispatch(setMapZoom({ zoom }))
80-
if (routerId) dispatch(setRouterId(routerId))
80+
// If router ID is provided, override the default routerId.
81+
if (routerId) {
82+
// This is a somewhat hidden element of the trip planner, so show a
83+
// confirmation message to the user to ensure they are aware of what
84+
// is happening.
85+
const useAltRouterId = window.confirm(
86+
`The trip planner's router is set to ${routerId}.\n\nClick OK to confirm or Cancel to use the default router.\n\nNote: new sessions opened with URLs copied from this tab's address bar will not reference the correct router (must contain the #/start/lat/lon/zoom/router prefix).`
87+
)
88+
if (useAltRouterId) dispatch(setRouterId(routerId))
89+
else dispatch(setRouterId(null))
90+
}
8191
dispatch(setMainPanelContent(null))
8292
break
8393
// For any other route path, just revert to default panel.

Diff for: lib/reducers/create-otp-reducer.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,12 @@ export function getInitialState (userDefinedConfig, initialQuery) {
125125
// This routerId session value is initially set by visiting otp-rr
126126
// with the path /start/:latLonZoomRouter, which dispatches the SET_ROUTER_ID
127127
// action and stores the value in sessionStorage.
128+
// Note: this mechanism assumes that the OTP API path is otp/routers/default.
128129
const routerId = window.sessionStorage.getItem('routerId')
130+
// If routerId is found, update the config.api.path (keep the original config
131+
// value at _path in case it needs to be reverted.)
129132
if (routerId) {
133+
config.api._path = userDefinedConfig.api.path
130134
config.api.path = `/otp/routers/${routerId}`
131135
}
132136
let queryModes = currentQuery.mode.split(',')
@@ -550,14 +554,23 @@ function createOtpReducer (config, initialQuery) {
550554
}
551555
})
552556
case 'SET_ROUTER_ID':
553-
const routerId = action.payload || 'default'
557+
const routerId = action.payload
558+
// Store original path value in _path variable.
559+
const _path = config.api._path || config.api.path || '/otp/routers/default'
560+
const path = routerId
561+
? `/otp/routers/${routerId}`
562+
// If routerId is null, revert to the original config's API path (or
563+
// the standard path if that is not found).
564+
: _path
554565
// Store routerId in session storage (persists through page reloads but
555566
// not when a new tab/window is opened).
556-
window.sessionStorage.setItem('routerId', routerId)
567+
if (routerId) window.sessionStorage.setItem('routerId', routerId)
568+
else window.sessionStorage.removeItem('routerId')
557569
return update(state, {
558570
config: {
559571
api: {
560-
path: { $set: `/otp/routers/${routerId}` }
572+
path: { $set: path },
573+
_path: { $set: _path }
561574
}
562575
}
563576
})

0 commit comments

Comments
 (0)