1
1
import React , { Component , PureComponent } from 'react'
2
+ import { connect } from 'react-redux'
2
3
3
4
import LocationIcon from '../../icons/location-icon'
4
5
import ViewStopButton from '../../viewers/view-stop-button'
5
- import { getPlaceName , isTransit } from '../../../util/itinerary'
6
+ import {
7
+ getCompanyForNetwork ,
8
+ getModeStringForCompany ,
9
+ getPlaceName ,
10
+ isTransit
11
+ } from '../../../util/itinerary'
6
12
import { formatTime } from '../../../util/time'
7
13
8
14
import TransitLegBody from './transit-leg-body'
@@ -11,7 +17,7 @@ import AccessLegBody from './access-leg-body'
11
17
// TODO: make this a prop
12
18
const defaultRouteColor = '#008'
13
19
14
- export default class PlaceRow extends Component {
20
+ class PlaceRow extends Component {
15
21
_createLegLine ( leg ) {
16
22
switch ( leg . mode ) {
17
23
case 'WALK' : return < div className = 'leg-line leg-line-walk' />
@@ -31,7 +37,7 @@ export default class PlaceRow extends Component {
31
37
32
38
/* eslint-disable complexity */
33
39
render ( ) {
34
- const { customIcons, leg, legIndex, place, time, timeOptions, followsTransit, previousLeg } = this . props
40
+ const { config , customIcons, leg, legIndex, place, time, timeOptions, followsTransit, previousLeg } = this . props
35
41
const stackIcon = ( name , color , size ) => < i className = { `fa fa-${ name } fa-stack-1x` } style = { { color, fontSize : size + 'px' } } />
36
42
37
43
let icon
@@ -59,6 +65,10 @@ export default class PlaceRow extends Component {
59
65
}
60
66
61
67
const interline = leg && leg . interlineWithPreviousLeg
68
+ // TODO: This changeVehicles condition might should be showing the full stop
69
+ // place name because it could be helpful to give the user the stop viewer to
70
+ // click on in order to see what time the next vehicle will be arriving to the
71
+ // shared stop.
62
72
const changeVehicles = previousLeg && previousLeg . to . stopId === leg . from . stopId && isTransit ( previousLeg . mode ) && isTransit ( leg . mode )
63
73
const special = interline || changeVehicles
64
74
return (
@@ -80,7 +90,7 @@ export default class PlaceRow extends Component {
80
90
? < div className = 'interline-name' > Stay on Board at < b > { place . name } </ b > </ div >
81
91
: changeVehicles
82
92
? < div className = 'interline-name' > Change Vehicles at < b > { place . name } </ b > </ div >
83
- : < div > { getPlaceName ( place ) } </ div >
93
+ : < div > { getPlaceName ( place , config . companies ) } </ div >
84
94
}
85
95
</ div >
86
96
@@ -92,22 +102,11 @@ export default class PlaceRow extends Component {
92
102
</ div >
93
103
) }
94
104
95
- { /* Place subheading: rented bike pickup */ }
96
- { leg && leg . rentedBike && (
97
- < div className = 'place-subheader' >
98
- Pick up shared bike
99
- </ div >
105
+ { /* Place subheading: rented vehicle (e.g., scooter, bike, car) pickup */ }
106
+ { leg && ( leg . rentedVehicle || leg . rentedBike || leg . rentedCar ) && (
107
+ < RentedVehicleLeg config = { config } leg = { leg } />
100
108
) }
101
109
102
- { /* Place subheading: rented car pickup */ }
103
- { leg && leg . rentedCar && (
104
- < div className = 'place-subheader' >
105
- Pick up { leg . from . networks ? leg . from . networks . join ( '/' ) : 'rented car' } { leg . from . name }
106
- </ div >
107
- ) }
108
-
109
- < RentedVehicleLeg leg = { leg } />
110
-
111
110
{ /* Show the leg, if present */ }
112
111
{ leg && (
113
112
leg . transitLeg
@@ -121,6 +120,7 @@ export default class PlaceRow extends Component {
121
120
)
122
121
: ( /* This is an access (e.g. walk/bike/etc.) leg */
123
122
< AccessLegBody
123
+ config = { config }
124
124
customIcons = { customIcons }
125
125
followsTransit = { followsTransit }
126
126
leg = { leg }
@@ -137,6 +137,20 @@ export default class PlaceRow extends Component {
137
137
}
138
138
}
139
139
140
+ // connect to the redux store
141
+
142
+ const mapStateToProps = ( state , ownProps ) => {
143
+ return {
144
+ // Pass config in order to give access to companies definition (used to
145
+ // determine proper place names for rental vehicles).
146
+ config : state . otp . config
147
+ }
148
+ }
149
+
150
+ const mapDispatchToProps = { }
151
+
152
+ export default connect ( mapStateToProps , mapDispatchToProps ) ( PlaceRow )
153
+
140
154
/**
141
155
* A component to display vehicle rental data. The word "Vehicle" has been used
142
156
* because a future refactor is intended to combine car rental, bike rental
@@ -146,8 +160,8 @@ export default class PlaceRow extends Component {
146
160
*/
147
161
class RentedVehicleLeg extends PureComponent {
148
162
render ( ) {
149
- const { leg} = this . props
150
- if ( ! leg || ! leg . rentedVehicle ) return null
163
+ const { config , leg } = this . props
164
+ const configCompanies = config . companies || [ ]
151
165
if ( leg . mode === 'WALK' ) {
152
166
return (
153
167
< div className = 'place-subheader' >
@@ -156,14 +170,23 @@ class RentedVehicleLeg extends PureComponent {
156
170
)
157
171
}
158
172
159
- if ( leg . rentedVehicleData ) {
173
+ if ( leg . rentedVehicle || leg . rentedBike || leg . rentedCar ) {
174
+ // console.log(leg.from.networks, configCompanies)
175
+ const companies = leg . from . networks . map ( n => getCompanyForNetwork ( n , configCompanies ) )
176
+ const companyLabel = companies . map ( co => co . label ) . join ( '/' )
177
+ const modeString = getModeStringForCompany ( companies [ 0 ] )
178
+ // Only show vehicle name for car rentals. For bikes and eScooters, these
179
+ // IDs/names tend to be less relevant (or entirely useless) in this context.
180
+ const vehicleName = leg . rentedCar ? ` ${ leg . from . name } ` : ''
181
+ // e.g., Pick up REACHNOW rented car XYZNDB OR
182
+ // Pick up SPIN eScooter
160
183
return (
161
184
< div className = 'place-subheader' >
162
- Pick up { leg . rentedVehicleData . companies . join ( '/' ) } vehicle { leg . from . name }
185
+ Pick up { companyLabel } { modeString } { vehicleName }
163
186
</ div >
164
187
)
165
188
}
166
-
189
+ // FIXME: Under what conditions would this be returned?
167
190
return (
168
191
< div className = 'place-subheader' >
169
192
Continue riding from { leg . from . name }
0 commit comments