1
1
import React , { Component } from 'react'
2
2
import PropTypes from 'prop-types'
3
3
4
- import ModeIcon from '../../icons/mode-icon'
5
4
import TripDetails from '../trip-details'
5
+ import { distanceString } from '../../../util/distance'
6
6
import { formatTime , formatDuration } from '../../../util/time'
7
- import { getLegModeLabel , getStepDirection , getStepStreetName , getTimeZoneOffset } from '../../../util/itinerary'
7
+ import {
8
+ getCompaniesLabelFromNetworks ,
9
+ getLegIcon ,
10
+ getLegModeLabel ,
11
+ getPlaceName ,
12
+ getStepDirection ,
13
+ getStepStreetName ,
14
+ getTimeZoneOffset
15
+ } from '../../../util/itinerary'
8
16
9
17
export default class PrintableItinerary extends Component {
10
18
static propTypes = {
11
19
itinerary : PropTypes . object
12
20
}
13
21
14
22
render ( ) {
15
- const { itinerary, timeFormat } = this . props
23
+ const {
24
+ configCompanies,
25
+ customIcons,
26
+ itinerary,
27
+ timeFormat
28
+ } = this . props
16
29
17
30
const timeOptions = {
18
31
format : timeFormat ,
@@ -31,10 +44,26 @@ export default class PrintableItinerary extends Component {
31
44
</ div >
32
45
) }
33
46
{ itinerary . legs . map ( ( leg , k ) => leg . transitLeg
34
- ? < TransitLeg key = { k } leg = { leg } interlineFollows = { k < itinerary . legs . length - 1 && itinerary . legs [ k + 1 ] . interlineWithPreviousLeg } timeOptions = { timeOptions } />
47
+ ? < TransitLeg
48
+ key = { k }
49
+ customIcons = { customIcons }
50
+ interlineFollows = { k < itinerary . legs . length - 1 &&
51
+ itinerary . legs [ k + 1 ] . interlineWithPreviousLeg
52
+ }
53
+ leg = { leg }
54
+ timeOptions = { timeOptions } />
35
55
: leg . hailedCar
36
- ? < TNCLeg leg = { leg } timeOptions = { timeOptions } />
37
- : < AccessLeg key = { k } leg = { leg } timeOptions = { timeOptions } />
56
+ ? < TNCLeg
57
+ customIcons = { customIcons }
58
+ leg = { leg }
59
+ timeOptions = { timeOptions } />
60
+ : < AccessLeg
61
+ key = { k }
62
+ configCompanies = { configCompanies }
63
+ customIcons = { customIcons }
64
+ leg = { leg }
65
+ timeOptions = { timeOptions }
66
+ />
38
67
) }
39
68
< TripDetails itinerary = { itinerary } />
40
69
</ div >
@@ -48,18 +77,23 @@ class TransitLeg extends Component {
48
77
}
49
78
50
79
render ( ) {
51
- const { leg, interlineFollows, timeOptions } = this . props
80
+ const { customIcons , leg, interlineFollows, timeOptions } = this . props
52
81
53
82
// Handle case of transit leg interlined w/ previous
54
83
if ( leg . interlineWithPreviousLeg ) {
55
84
return (
56
85
< div className = 'leg collapse-top' >
57
86
< div className = 'leg-body' >
58
87
< div className = 'leg-header' >
59
- Continues as < b > { leg . routeShortName } { leg . routeLongName } </ b > to < b > { leg . to . name } </ b >
88
+ Continues as{ ' ' }
89
+ < b > { leg . routeShortName } { leg . routeLongName } </ b > { ' ' }
90
+ to < b > { leg . to . name } </ b >
60
91
</ div >
61
92
< div className = 'leg-details' >
62
- < div className = 'leg-detail' > Get off at < b > { leg . to . name } </ b > at { formatTime ( leg . endTime , timeOptions ) } </ div >
93
+ < div className = 'leg-detail' >
94
+ Get off at < b > { leg . to . name } </ b > { ' ' }
95
+ at { formatTime ( leg . endTime , timeOptions ) }
96
+ </ div >
63
97
</ div >
64
98
</ div >
65
99
</ div >
@@ -68,17 +102,25 @@ class TransitLeg extends Component {
68
102
69
103
return (
70
104
< div className = 'leg' >
71
- < div className = 'mode-icon' > < ModeIcon mode = { leg . mode } /> </ div >
105
+ < div className = 'mode-icon' > { getLegIcon ( leg , customIcons ) } </ div >
72
106
< div className = 'leg-body' >
73
107
< div className = 'leg-header' >
74
108
< b > { leg . routeShortName } { leg . routeLongName } </ b > to < b > { leg . to . name } </ b >
75
109
</ div >
76
110
< div className = 'leg-details' >
77
- < div className = 'leg-detail' > Board at < b > { leg . from . name } </ b > at { formatTime ( leg . startTime , timeOptions ) } </ div >
78
- { interlineFollows
79
- ? < div className = 'leg-detail' > Stay on board at < b > { leg . to . name } </ b > </ div >
80
- : < div className = 'leg-detail' > Get off at < b > { leg . to . name } </ b > at { formatTime ( leg . endTime , timeOptions ) } </ div >
81
- }
111
+ < div className = 'leg-detail' >
112
+ Board at < b > { leg . from . name } </ b > { ' ' }
113
+ at { formatTime ( leg . startTime , timeOptions ) }
114
+ </ div >
115
+ < div className = 'leg-detail' >
116
+ { interlineFollows
117
+ ? < span > Stay on board at < b > { leg . to . name } </ b > </ span >
118
+ : < span >
119
+ Get off at < b > { leg . to . name } </ b > { ' ' }
120
+ at { formatTime ( leg . endTime , timeOptions ) }
121
+ </ span >
122
+ }
123
+ </ div >
82
124
</ div >
83
125
</ div >
84
126
</ div >
@@ -92,19 +134,49 @@ class AccessLeg extends Component {
92
134
}
93
135
94
136
render ( ) {
95
- const { leg } = this . props
137
+ const { configCompanies, customIcons, leg } = this . props
138
+
139
+ // calculate leg mode label in a special way for this component
140
+ let legModeLabel = getLegModeLabel ( leg )
141
+
142
+ if ( leg . rentedBike ) {
143
+ // FIXME: Special case for TriMet that needs to be refactored to
144
+ // incorporate actual company.
145
+ legModeLabel = 'Ride BIKETOWN bike'
146
+ } else if ( leg . rentedCar ) {
147
+ // Add extra information to printview that would otherwise clutter up
148
+ // other places that use the getLegModeLabel function
149
+ const companiesLabel = getCompaniesLabelFromNetworks (
150
+ leg . from . networks ,
151
+ configCompanies
152
+ )
153
+ legModeLabel = `Drive ${ companiesLabel } ${ leg . from . name } `
154
+ } else if ( leg . rentedVehicle ) {
155
+ const companiesLabel = getCompaniesLabelFromNetworks (
156
+ leg . from . networks ,
157
+ configCompanies
158
+ )
159
+ legModeLabel = `Ride ${ companiesLabel } eScooter`
160
+ }
161
+
96
162
return (
97
163
< div className = 'leg' >
98
- < div className = 'mode-icon' > < ModeIcon mode = { leg . mode } /> </ div >
164
+ < div className = 'mode-icon' > { getLegIcon ( leg , customIcons ) } </ div >
99
165
< div className = 'leg-body' >
100
166
< div className = 'leg-header' >
101
- < b > { getLegModeLabel ( leg ) } </ b > to < b > { leg . to . name } </ b >
167
+ < b > { legModeLabel } </ b > { ' ' }
168
+ { ! leg . hailedCar &&
169
+ leg . distance > 0 &&
170
+ < span > { distanceString ( leg . distance ) } </ span > }
171
+ to < b > { getPlaceName ( leg . to , configCompanies ) } </ b >
102
172
</ div >
103
173
{ ! leg . hailedCar && (
104
174
< div className = 'leg-details' >
105
175
{ leg . steps . map ( ( step , k ) => {
106
176
return (
107
- < div key = { k } className = 'leg-detail' > { getStepDirection ( step ) } on < b > { getStepStreetName ( step ) } </ b > </ div >
177
+ < div key = { k } className = 'leg-detail' >
178
+ { getStepDirection ( step ) } on < b > { getStepStreetName ( step ) } </ b >
179
+ </ div >
108
180
)
109
181
} ) }
110
182
</ div >
@@ -121,20 +193,26 @@ class TNCLeg extends Component {
121
193
}
122
194
123
195
render ( ) {
124
- const { leg } = this . props
196
+ const { customIcons , leg } = this . props
125
197
const { tncData } = leg
126
198
if ( ! tncData ) return null
127
199
128
200
return (
129
201
< div className = 'leg' >
130
- < div className = 'mode-icon' > < ModeIcon mode = { leg . mode } /> </ div >
202
+ < div className = 'mode-icon' > { getLegIcon ( leg , customIcons ) } </ div >
131
203
< div className = 'leg-body' >
132
204
< div className = 'leg-header' >
133
205
< b > Take { tncData . displayName } </ b > to < b > { leg . to . name } </ b >
134
206
</ div >
135
207
< div className = 'leg-details' >
136
- < div className = 'leg-detail' > Estimated wait time for pickup: < b > { formatDuration ( tncData . estimatedArrival ) } </ b > </ div >
137
- < div className = 'leg-detail' > Estimated travel time: < b > { formatDuration ( leg . duration ) } </ b > (does not account for traffic)</ div >
208
+ < div className = 'leg-detail' >
209
+ Estimated wait time for pickup:{ ' ' }
210
+ < b > { formatDuration ( tncData . estimatedArrival ) } </ b >
211
+ </ div >
212
+ < div className = 'leg-detail' >
213
+ Estimated travel time:{ ' ' }
214
+ < b > { formatDuration ( leg . duration ) } </ b > (does not account for traffic)
215
+ </ div >
138
216
</ div >
139
217
</ div >
140
218
</ div >
0 commit comments