-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathmain.js
126 lines (104 loc) · 3.67 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import MobileDateTimeScreen from './date-time-screen'
import MobileOptionsScreen from './options-screen'
import MobileLocationSearch from './location-search'
import MobileWelcomeScreen from './welcome-screen'
import MobileStopViewer from './stop-viewer'
import MobileTripViewer from './trip-viewer'
import MobileRouteViewer from './route-viewer'
import { MobileScreens, MainPanelContent, setMobileScreen } from '../../actions/ui'
import { ComponentContext } from '../../util/contexts'
import { getActiveItinerary } from '../../util/state'
class MobileMain extends Component {
static propTypes = {
currentQuery: PropTypes.object,
map: PropTypes.element,
setMobileScreen: PropTypes.func,
title: PropTypes.element,
uiState: PropTypes.object
}
static contextType = ComponentContext
componentDidUpdate (prevProps) {
// Check if we are in the welcome screen and both locations have been set OR
// auto-detect is denied and one location is set
if (
prevProps.uiState.mobileScreen === MobileScreens.WELCOME_SCREEN && (
(this.props.currentQuery.from && this.props.currentQuery.to) ||
(!this.props.currentPosition.coords && (this.props.currentQuery.from || this.props.currentQuery.to))
)
) {
// If so, advance to main search screen
this.props.setMobileScreen(MobileScreens.SEARCH_FORM)
}
if (!prevProps.activeItinerary && this.props.activeItinerary) {
this.props.setMobileScreen(MobileScreens.RESULTS_SUMMARY)
}
}
render () {
const { MobileResultsScreen, MobileSearchScreen } = this.context
const { uiState } = this.props
// check for route viewer
if (uiState.mainPanelContent === MainPanelContent.ROUTE_VIEWER) {
return <MobileRouteViewer />
}
// check for viewed stop
if (uiState.viewedStop) return <MobileStopViewer />
// check for viewed trip
if (uiState.viewedTrip) return <MobileTripViewer />
switch (uiState.mobileScreen) {
case MobileScreens.WELCOME_SCREEN:
return <MobileWelcomeScreen />
case MobileScreens.SET_INITIAL_LOCATION:
return (
<MobileLocationSearch
locationType='to'
backScreen={MobileScreens.WELCOME_SCREEN}
/>
)
case MobileScreens.SEARCH_FORM:
// Render batch search screen if batch routing enabled. Otherwise,
// default to standard search screen.
return (
<MobileSearchScreen newScreen={this.newScreen} />
)
case MobileScreens.SET_FROM_LOCATION:
return (
<MobileLocationSearch
locationType='from'
backScreen={MobileScreens.SEARCH_FORM}
/>
)
case MobileScreens.SET_TO_LOCATION:
return (
<MobileLocationSearch
locationType='to'
backScreen={MobileScreens.SEARCH_FORM}
/>
)
case MobileScreens.SET_DATETIME:
return <MobileDateTimeScreen />
case MobileScreens.SET_OPTIONS:
return <MobileOptionsScreen />
case MobileScreens.RESULTS_SUMMARY:
return <MobileResultsScreen />
default:
return <p>Invalid mobile screen</p>
}
}
}
// connect to the redux store
const mapStateToProps = (state, ownProps) => {
return {
config: state.otp.config,
uiState: state.otp.ui,
currentQuery: state.otp.currentQuery,
currentPosition: state.otp.location.currentPosition,
activeItinerary: getActiveItinerary(state.otp)
}
}
const mapDispatchToProps = {
setMobileScreen
}
export default connect(mapStateToProps, mapDispatchToProps)(MobileMain)