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
7
import {
8
+ getCompaniesLabelFromNetworks ,
9
+ getLegIcon ,
8
10
getLegModeLabel ,
9
11
getPlaceName ,
10
12
getStepDirection ,
@@ -18,7 +20,12 @@ export default class PrintableItinerary extends Component {
18
20
}
19
21
20
22
render ( ) {
21
- const { companies, itinerary, timeFormat } = this . props
23
+ const {
24
+ configCompanies,
25
+ customIcons,
26
+ itinerary,
27
+ timeFormat
28
+ } = this . props
22
29
23
30
const timeOptions = {
24
31
format : timeFormat ,
@@ -39,20 +46,24 @@ export default class PrintableItinerary extends Component {
39
46
{ itinerary . legs . map ( ( leg , k ) => leg . transitLeg
40
47
? < TransitLeg
41
48
key = { k }
42
- leg = { leg }
49
+ customIcons = { customIcons }
43
50
interlineFollows = { k < itinerary . legs . length - 1 &&
44
51
itinerary . legs [ k + 1 ] . interlineWithPreviousLeg
45
52
}
53
+ leg = { leg }
46
54
timeOptions = { timeOptions } />
47
55
: leg . hailedCar
48
56
? < TNCLeg
57
+ customIcons = { customIcons }
49
58
leg = { leg }
50
59
timeOptions = { timeOptions } />
51
60
: < AccessLeg
52
61
key = { k }
62
+ configCompanies = { configCompanies }
63
+ customIcons = { customIcons }
53
64
leg = { leg }
54
65
timeOptions = { timeOptions }
55
- companies = { companies } />
66
+ />
56
67
) }
57
68
< TripDetails itinerary = { itinerary } />
58
69
</ div >
@@ -66,7 +77,7 @@ class TransitLeg extends Component {
66
77
}
67
78
68
79
render ( ) {
69
- const { leg, interlineFollows, timeOptions } = this . props
80
+ const { customIcons , leg, interlineFollows, timeOptions } = this . props
70
81
71
82
// Handle case of transit leg interlined w/ previous
72
83
if ( leg . interlineWithPreviousLeg ) {
@@ -91,7 +102,7 @@ class TransitLeg extends Component {
91
102
92
103
return (
93
104
< div className = 'leg' >
94
- < div className = 'mode-icon' > < ModeIcon mode = { leg . mode } /> </ div >
105
+ < div className = 'mode-icon' > { getLegIcon ( leg , customIcons ) } </ div >
95
106
< div className = 'leg-body' >
96
107
< div className = 'leg-header' >
97
108
< b > { leg . routeShortName } { leg . routeLongName } </ b > to < b > { leg . to . name } </ b >
@@ -123,14 +134,41 @@ class AccessLeg extends Component {
123
134
}
124
135
125
136
render ( ) {
126
- const { companies, 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
+
127
162
return (
128
163
< div className = 'leg' >
129
- < div className = 'mode-icon' > < ModeIcon mode = { leg . mode } /> </ div >
164
+ < div className = 'mode-icon' > { getLegIcon ( leg , customIcons ) } </ div >
130
165
< div className = 'leg-body' >
131
166
< div className = 'leg-header' >
132
- < b > { getLegModeLabel ( leg ) } </ b > { ' ' }
133
- to < b > { getPlaceName ( leg . to , companies ) } </ 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 >
134
172
</ div >
135
173
{ ! leg . hailedCar && (
136
174
< div className = 'leg-details' >
@@ -155,13 +193,13 @@ class TNCLeg extends Component {
155
193
}
156
194
157
195
render ( ) {
158
- const { leg } = this . props
196
+ const { customIcons , leg } = this . props
159
197
const { tncData } = leg
160
198
if ( ! tncData ) return null
161
199
162
200
return (
163
201
< div className = 'leg' >
164
- < div className = 'mode-icon' > < ModeIcon mode = { leg . mode } /> </ div >
202
+ < div className = 'mode-icon' > { getLegIcon ( leg , customIcons ) } </ div >
165
203
< div className = 'leg-body' >
166
204
< div className = 'leg-header' >
167
205
< b > Take { tncData . displayName } </ b > to < b > { leg . to . name } </ b >
0 commit comments