Skip to content
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
30 changes: 23 additions & 7 deletions lib/components/app/responsive-webapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,34 @@ class ResponsiveWebapp extends Component {
}

componentDidMount () {
const {
getCurrentPosition,
handleBackButtonPress,
initializeModules,
location,
matchContentToUrl,
parseUrlQueryString,
receivedPositionResponse,
title
} = this.props
// Add on back button press behavior.
window.addEventListener('popstate', this.props.handleBackButtonPress)
const { location, title } = this.props
window.addEventListener('popstate', handleBackButtonPress)
document.title = title
if (window.location.search) {
// If a URL is detected without hash routing (e.g., http://localhost:9966?sessionId=test),
// window.location.search will have a value. In this case, we need to redirect to the URL root with the
// search reconstructed for use with the hash router. This redirect should cause little disruption.
window.location.href = `${URL_ROOT}/#/${window.location.search}`
return
}
if (isMobile()) {
// If on mobile browser, check position on load
this.props.getCurrentPosition()
getCurrentPosition()

// Also, watch for changes in position on mobile
navigator.geolocation.watchPosition(
// On success
position => { this.props.receivedPositionResponse({ position }) },
position => { receivedPositionResponse({ position }) },
// On error
error => { console.log('error in watchPosition', error) },
// Options
Expand All @@ -129,14 +145,14 @@ class ResponsiveWebapp extends Component {
// Handle routing to a specific part of the app (e.g. stop viewer) on page
// load. (This happens prior to routing request in case special routerId is
// set from URL.)
this.props.matchContentToUrl(this.props.location)
matchContentToUrl(location)
if (location && location.search) {
// Set search params and plan trip if routing enabled and a query exists
// in the URL.
this.props.parseUrlQueryString()
parseUrlQueryString()
}
// Initialize call taker/field trip modules (check for valid auth session).
this.props.initializeModules()
initializeModules()
}

componentWillUnmount () {
Expand Down