Skip to content

Commit 83ebd5c

Browse files
author
David Emory
committed
feat(overlay): Refine/enhance bike station overlay
Add icons for hubs/floating bikes. Add simple station info popup. Refresh periodically using timer.
1 parent 00e7230 commit 83ebd5c

File tree

2 files changed

+68
-14
lines changed

2 files changed

+68
-14
lines changed

lib/components/map/bike-rental-overlay.js

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { Component, PropTypes } from 'react'
1+
import React, { Component, PropTypes } from 'react'
22
import { connect } from 'react-redux'
3+
import { Marker, Popup } from 'react-leaflet'
4+
import { divIcon } from 'leaflet'
35

46
import { bikeRentalQuery } from '../../actions/api'
57

@@ -10,28 +12,62 @@ class BikeRentalOverlay extends Component {
1012
}
1113

1214
componentDidMount () {
13-
console.log('refreshing bike stations');
14-
this.state.refreshStations()
15+
// ititial station retrieval
16+
this.props.refreshStations()
17+
18+
// set up timer to refresh stations periodically
19+
this._refreshTimer = setInterval(() => {
20+
this.props.refreshStations()
21+
}, 30000) // defaults to every 30 sec. TODO: make this configurable?
22+
}
23+
24+
componentWillUnmount () {
25+
clearInterval(this._refreshTimer)
1526
}
1627

1728
render () {
18-
// const { from, to } = this.props.query
19-
console.log('render stations: ' + this.props.stations)
20-
return null
21-
/*return (
29+
return (
2230
<div>
23-
<Endpoint type='from' location={from} {...this.props} />
24-
<Endpoint type='to' location={to} {...this.props} />
31+
{this.props.stations.map((station) => {
32+
const icon = station.isFloatingBike
33+
? divIcon({
34+
html: `<i class="fa fa-bicycle fa-stack-2x" style="color: #000000"></i>`,
35+
className: ''
36+
})
37+
: divIcon({
38+
html: `<i class="fa fa-circle fa-stack-2x" style="color: #000000"></i>`,
39+
className: ''
40+
})
41+
return (
42+
<Marker
43+
icon={icon}
44+
position={[station.y, station.x]}
45+
>
46+
<Popup>
47+
{station.isFloatingBike
48+
? <span>
49+
<b>Floating bike: {station.name}</b>
50+
</span>
51+
: <span>
52+
<b>{station.name}</b><br />
53+
Available bikes: {station.bikesAvailable}<br />
54+
Available docks: {station.spacesAvailable}<br />
55+
</span>
56+
}
57+
</Popup>
58+
</Marker>
59+
)
60+
})}
2561
</div>
26-
)*/
62+
)
2763
}
2864
}
2965

3066
// connect to the redux store
3167

3268
const mapStateToProps = (state, ownProps) => {
3369
return {
34-
stations: state.otp.overlay.bike_rental.stations
70+
stations: state.otp.overlay.bikeRental.stations
3571
}
3672
}
3773

lib/reducers/create-otp-reducer.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function createOtpReducer (config, initialQuery) {
3333
searches: [],
3434
activeSearch: 0,
3535
overlay: {
36-
bike_rental: {
36+
bikeRental: {
3737
stations: []
3838
}
3939
}
@@ -73,11 +73,29 @@ function createOtpReducer (config, initialQuery) {
7373
}},
7474
activeSearch: { $set: latestSearchIndex }
7575
})
76+
case 'BIKE_RENTAL_REQUEST':
77+
return update(state, {
78+
overlay: {
79+
bikeRental: {
80+
pending: {$set: true},
81+
error: {$set: null}
82+
}
83+
}
84+
})
85+
case 'BIKE_RENTAL_ERROR':
86+
return update(state, {
87+
overlay: {
88+
bikeRental: {
89+
pending: {$set: false},
90+
error: {$set: action.payload}
91+
}
92+
}
93+
})
7694
case 'BIKE_RENTAL_RESPONSE':
7795
return update(state, {
7896
overlay: {
79-
bike_rental: {
80-
stations: {$set: action.payload},
97+
bikeRental: {
98+
stations: {$set: action.payload.stations},
8199
pending: {$set: false}
82100
}
83101
}

0 commit comments

Comments
 (0)