Skip to content

Commit 3d1bbb5

Browse files
committed
fix(routerId): if routerId present, include in copied URL
1 parent e97b58f commit 3d1bbb5

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

Diff for: lib/actions/ui.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ export function matchContentToUrl (location) {
7070
// Parse comma separated params (ensuring numbers are parsed correctly).
7171
let [lat, lon, zoom, routerId] = id ? idToParams(id) : []
7272
if (!lat || !lon) {
73-
// Attempt to parse path. (Legacy UI otp.js used slashes in the
74-
// pathname to specify lat, lon, etc.)
73+
// Attempt to parse path if lat/lon not found. (Legacy UI otp.js used
74+
// slashes in the pathname to specify lat, lon, etc.)
7575
[,, lat, lon, zoom, routerId] = idToParams(location.pathname, '/')
7676
}
77+
console.log(lat, lon, zoom, routerId)
7778
// Update map location/zoom and optionally override router ID.
78-
dispatch(setMapCenter({ lat, lon }))
79-
dispatch(setMapZoom({ zoom }))
79+
if (+lat && +lon) dispatch(setMapCenter({ lat, lon }))
80+
if (+zoom) dispatch(setMapZoom({ zoom }))
8081
// If router ID is provided, override the default routerId.
8182
if (routerId) dispatch(setRouterId(routerId))
8283
dispatch(setMainPanelContent(null))
@@ -89,6 +90,10 @@ export function matchContentToUrl (location) {
8990
}
9091
}
9192

93+
/**
94+
* Split the path id into its parts (according to specified delimiter). Parse
95+
* numbers if detected.
96+
*/
9297
function idToParams (id, delimiter = ',') {
9398
return id.split(delimiter).map(s => isNaN(s) ? s : +s)
9499
}

Diff for: lib/components/app/responsive-webapp.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,20 @@ class ResponsiveWebapp extends Component {
105105
{ enableHighAccuracy: true }
106106
)
107107
}
108-
108+
// Handle routing to a specific part of the app (e.g. stop viewer) on page
109+
// load. (This happens prior to routing request in case special routerId is
110+
// set from URL.)
111+
this.props.matchContentToUrl(this.props.location)
109112
if (location && location.search) {
110113
// Set search params and plan trip if routing enabled and a query exists
111114
// in the URL.
112115
this.props.parseUrlQueryString()
113116
}
114-
// Handle routing to a specific part of the app (e.g. stop viewer) on page
115-
// load.
116-
this.props.matchContentToUrl(this.props.location)
117117
}
118118

119119
componentWillUnmount () {
120120
// Remove on back button press listener.
121-
window.removeEventListener('popstate')
121+
window.removeEventListener('popstate', this.props.handleBackButtonPress)
122122
}
123123

124124
render () {

Diff for: lib/components/narrative/trip-tools.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,24 @@ class CopyUrlButton extends Component {
7777
this.state = { showCopied: false }
7878
}
7979

80+
_resetState = () => this.setState({ showCopied: false })
81+
8082
_onClick = () => {
81-
copyToClipboard(window.location.href)
83+
// If special routerId has been set in session storage, construct copy URL
84+
// for itinerary with #/start/ prefix to set routerId on page load.
85+
const routerId = window.sessionStorage.getItem('routerId')
86+
let url = window.location.href
87+
if (routerId) {
88+
const parts = url.split('#')
89+
if (parts.length === 2) {
90+
url = `${parts[0]}#/start/x/x/x/${routerId}${parts[1]}`
91+
} else {
92+
console.warn('URL not formatted as expected, copied URL will not contain session routerId.', routerId)
93+
}
94+
}
95+
copyToClipboard(url)
8296
this.setState({ showCopied: true })
83-
setTimeout(() => { this.setState({ showCopied: false }) }, 2000)
97+
window.setTimeout(this._resetState, 2000)
8498
}
8599

86100
render () {

0 commit comments

Comments
 (0)