-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
129 lines (115 loc) · 3.13 KB
/
example.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
127
128
129
// import this polyfill in order to make webapp compatible with IE 11
import 'es6-math'
import { createHashHistory } from 'history'
import { connectRouter, routerMiddleware } from 'connected-react-router'
import React, { Component } from 'react'
import { render } from 'react-dom'
import { createStore, combineReducers, applyMiddleware, compose } from 'redux'
import { Provider } from 'react-redux'
import thunk from 'redux-thunk'
import createLogger from 'redux-logger'
// import Bootstrap Grid components for layout
import { Navbar, Grid, Row, Col } from 'react-bootstrap'
// import OTP-RR components
import {
DefaultSearchForm,
ErrorMessage,
MobileMain,
NarrativeRoutingResults,
ResponsiveWebapp,
Map,
ViewerContainer,
AppMenu,
createOtpReducer
} from './lib'
// load the OTP configuration
import otpConfig from './config.yml'
// create an initial query for demo/testing purposes
const initialQuery = {
from: {
lat: 45.5246,
lon: -122.6710
},
to: {
lat: 45.5307,
lon: -122.6647
},
type: 'ITINERARY'
}
const history = createHashHistory()
const middleware = [
thunk,
routerMiddleware(history) // for dispatching history actions
]
// check if app is being run in development mode. If so, enable redux-logger
if (process.env.NODE_ENV === 'development') {
middleware.push(createLogger())
}
// set up the Redux store
const store = createStore(
combineReducers({
otp: createOtpReducer(otpConfig),
router: connectRouter(history)
}),
compose(applyMiddleware(...middleware))
)
// define a simple responsive UI using Bootstrap and OTP-RR
class OtpRRExample extends Component {
render () {
/** desktop view **/
const desktopView = (
<div className='otp'>
<Navbar>
<Navbar.Header>
<Navbar.Brand>
<div style={{ float: 'left', color: 'white', fontSize: 28 }}>
<AppMenu />
</div>
<div className='navbar-title' style={{ marginLeft: 50 }}>OpenTripPlanner</div>
</Navbar.Brand>
</Navbar.Header>
</Navbar>
<Grid>
<Row className='main-row'>
<Col sm={6} md={4} className='sidebar'>
<ViewerContainer>
<DefaultSearchForm />
<ErrorMessage />
<div className='desktop-narrative-container'>
<NarrativeRoutingResults />
</div>
</ViewerContainer>
</Col>
<Col sm={6} md={8} className='map-container'>
<Map />
</Col>
</Row>
</Grid>
</div>
)
/** mobile view **/
const mobileView = (
<MobileMain map={(<Map />)} title={(<div className='navbar-title'>OpenTripPlanner</div>)} />
)
/** the main webapp **/
return (
<ResponsiveWebapp
desktopView={desktopView}
mobileView={mobileView}
/>
)
}
}
// render the app
render(
<Provider store={store}>
{ /**
* If not using router history, simply include OtpRRExample here:
* e.g.
* <OtpRRExample />
*/
}
<OtpRRExample />
</Provider>,
document.getElementById('root')
)