Skip to content

Commit d723aef

Browse files
author
David Emory
authored
Merge pull request #28 from opentripplanner/dev
Mobile support
2 parents 41a3e02 + 3a4f0d0 commit d723aef

File tree

7 files changed

+99
-41
lines changed

7 files changed

+99
-41
lines changed

Diff for: lib/actions/config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { createAction } from 'redux-actions'
2+
3+
export const setAutoPlan = createAction('SET_AUTOPLAN')

Diff for: lib/components/form/date-time-selector.js

+44-27
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
// import moment from 'moment'
22
import React, {PropTypes, Component} from 'react'
3-
import { Form, FormGroup, FormControl } from 'react-bootstrap'
3+
import { Form, FormGroup, FormControl, Row, Col } from 'react-bootstrap'
44
// import { SingleDatePicker } from 'react-dates'
55
import { connect } from 'react-redux'
66

77
import { setDepart, setDate, setTime } from '../../actions/form'
88

99
class DateTimeSelector extends Component {
1010
static propTypes = {
11+
date: PropTypes.string,
12+
departArrive: PropTypes.string,
13+
time: PropTypes.string,
1114
location: PropTypes.object,
1215
label: PropTypes.string,
16+
setDate: PropTypes.func,
17+
setDepart: PropTypes.func,
1318
setLocation: PropTypes.func,
19+
setTime: PropTypes.func,
1420
type: PropTypes.string // replace with locationType?
1521
}
1622
constructor (props) {
@@ -36,32 +42,43 @@ class DateTimeSelector extends Component {
3642
const options = ['NOW', 'DEPART', 'ARRIVE']
3743
// TODO: choose date / time selectors (currently Chrome optimized)
3844
return (
39-
<Form inline>
40-
<FormGroup style={{marginBottom: '15px'}}>
41-
<FormControl
42-
componentClass='select'
43-
value={departArrive}
44-
onChange={this._onDepartChange}
45-
style={{width: '100px'}}
46-
>
47-
{options.map((o, i) => (
48-
<option key={i} value={o}>{o}</option>
49-
))}
50-
</FormControl>
51-
{' '}
52-
<FormControl
53-
type='date'
54-
value={date}
55-
onChange={this._onDateChange}
56-
style={{width: '160px', display: departArrive === 'NOW' && 'none'}}
57-
/>
58-
{' '}
59-
<FormControl
60-
type='time'
61-
value={time}
62-
onChange={this._onTimeChange}
63-
style={{width: '123px', display: departArrive === 'NOW' && 'none'}}
64-
/>
45+
<Form>
46+
<FormGroup style={{marginBottom: '15px'}} className='date-time-selector'>
47+
<Row>
48+
<Col xs={6}>
49+
<FormControl
50+
componentClass='select'
51+
value={departArrive}
52+
onChange={this._onDepartChange}
53+
style={{width: '100%'}}
54+
>
55+
{options.map((o, i) => (
56+
<option key={i} value={o}>{o}</option>
57+
))}
58+
</FormControl>
59+
</Col>
60+
<Col>{ }</Col>
61+
</Row>
62+
<Row style={{ marginTop: 10 }}>
63+
<Col xs={6}>
64+
<FormControl
65+
className='date-selector'
66+
type='date'
67+
value={date}
68+
onChange={this._onDateChange}
69+
style={{width: '100%', display: departArrive === 'NOW' && 'none'}}
70+
/>
71+
</Col>
72+
<Col xs={6}>
73+
<FormControl
74+
className='time-selector'
75+
type='time'
76+
value={time}
77+
onChange={this._onTimeChange}
78+
style={{width: '100%', display: departArrive === 'NOW' && 'none'}}
79+
/>
80+
</Col>
81+
</Row>
6582
</FormGroup>
6683
</Form>
6784
)

Diff for: lib/components/form/mode-selector.js

+29-7
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,50 @@ import { setMode } from '../../actions/form'
66

77
class ModeSelector extends Component {
88
static propTypes = {
9-
location: PropTypes.object,
9+
config: PropTypes.object,
1010
label: PropTypes.string,
11-
setLocation: PropTypes.func,
12-
type: PropTypes.string // replace with locationType?
11+
mode: PropTypes.string,
12+
setMode: PropTypes.func,
13+
showLabel: PropTypes.boolean
1314
}
15+
16+
static defaultProps = {
17+
label: 'Mode',
18+
showLabel: true
19+
}
20+
1421
_onChange = (evt) => {
1522
console.log(evt.target.value)
1623
this.props.setMode(evt.target.value)
1724
}
25+
26+
_getDisplayText (mode) {
27+
switch (mode) {
28+
case 'TRANSIT,WALK': return 'Walk to Transit'
29+
case 'TRANSIT,BICYCLE': return 'Bike to Transit'
30+
case 'WALK': return 'Walk Only'
31+
case 'BICYCLE': return 'Bike Only'
32+
}
33+
return mode
34+
}
35+
1836
render () {
19-
const { config, mode } = this.props
37+
const { config, mode, label, showLabel } = this.props
38+
2039
return (
2140
<form>
22-
<FormGroup>
23-
<ControlLabel>Mode:</ControlLabel>
41+
<FormGroup className='mode-selector'>
42+
{showLabel
43+
? <ControlLabel>{label}</ControlLabel>
44+
: null
45+
}
2446
<FormControl
2547
componentClass='select'
2648
value={mode}
2749
onChange={this._onChange}
2850
>
2951
{config.modes.map((m, i) => (
30-
<option key={i} value={m}>{m}</option>
52+
<option key={i} value={m}>{this._getDisplayText(m)}</option>
3153
))}
3254
</FormControl>
3355
</FormGroup>

Diff for: lib/components/form/plan-trip-button.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ import { planTrip } from '../../actions/api'
66

77
class PlanTripButton extends Component {
88
static propTypes = {
9-
onClick: PropTypes.func
9+
onClick: PropTypes.func,
10+
text: PropTypes.string
1011
}
1112
_onClick = () => {
1213
this.props.planTrip()
1314
}
1415
render () {
1516
return (
1617
<Button
18+
className='plan-trip-button'
1719
onClick={this._onClick || this.props.onClick}
18-
>Plan Trip</Button>
20+
>{this.props.text || 'Plan Trip'}</Button>
1921
)
2022
}
2123
}

Diff for: lib/components/narrative/itinerary-carousel.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ class ItineraryCarousel extends Component {
1616
pending: PropTypes.bool,
1717
activeItinerary: PropTypes.number,
1818
hideHeader: PropTypes.bool,
19+
onExpand: PropTypes.func,
1920
setActiveItinerary: PropTypes.func,
2021
setActiveLeg: PropTypes.func,
2122
setActiveStep: PropTypes.func
2223
}
2324

2425
_onItineraryClick = () => {
25-
this.setState({expanded: !this.state.expanded})
26+
const expanded = !this.state.expanded
27+
this.setState({expanded})
28+
if (this.props.onExpand) this.props.onExpand(expanded)
2629
}
2730

2831
_onLeftClick = () => {

Diff for: lib/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import ItineraryCarousel from './components/narrative/itinerary-carousel'
1515
import NarrativeItineraries from './components/narrative/narrative-itineraries'
1616
import NarrativeItinerary from './components/narrative/narrative-itinerary'
1717

18+
import { setAutoPlan } from './actions/config'
19+
1820
import createOtpReducer from './reducers/create-otp-reducer'
1921

2022
export {
@@ -38,6 +40,9 @@ export {
3840
NarrativeItineraries,
3941
NarrativeItinerary,
4042

43+
// actions
44+
setAutoPlan,
45+
4146
// redux utilities
4247
createOtpReducer
4348
}

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

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import update from 'immutability-helper'
44
// import { getDefaultQuery } from '../util/state'
55
import { getCurrentDate, getCurrentTime } from '../util/time'
66

7+
const defaultConfig = {
8+
autoPlan: true,
9+
debouncePlanTimeMs: 0
10+
}
11+
712
// TODO: parse query params
813
const defaultQuery = {
914
type: 'ITINERARY',
@@ -23,10 +28,7 @@ function createOtpReducer (config, initialQuery) {
2328
// populate query by merging any provided query params w/ the default params
2429
const currentQuery = Object.assign(defaultQuery, initialQuery)
2530
const initialState = {
26-
config: Object.assign({
27-
autoPlan: true,
28-
debouncePlanTimeMs: 0
29-
}, config),
31+
config: Object.assign(defaultConfig, config),
3032
currentQuery,
3133
searches: [],
3234
activeSearch: 0
@@ -102,6 +104,10 @@ function createOtpReducer (config, initialQuery) {
102104
return update(state, { currentQuery: { time: { $set: action.payload.time } } })
103105
case 'FORM_CHANGED':
104106
return update(state, { activeSearch: { $set: null } })
107+
108+
case 'SET_AUTOPLAN':
109+
return update(state, { config: { autoPlan: { $set: action.payload.autoPlan } } })
110+
105111
default:
106112
return state
107113
}

0 commit comments

Comments
 (0)