11import React , { Component } from 'react'
22import PropTypes from 'prop-types'
33
4- import ModeIcon from '../../icons/mode-icon'
54import TripDetails from '../trip-details'
5+ import { distanceString } from '../../../util/distance'
66import { formatTime , formatDuration } from '../../../util/time'
77import {
8+ getCompaniesLabelFromNetworks ,
9+ getLegIcon ,
810 getLegModeLabel ,
911 getPlaceName ,
1012 getStepDirection ,
@@ -18,7 +20,12 @@ export default class PrintableItinerary extends Component {
1820 }
1921
2022 render ( ) {
21- const { companies, itinerary, timeFormat } = this . props
23+ const {
24+ configCompanies,
25+ customIcons,
26+ itinerary,
27+ timeFormat
28+ } = this . props
2229
2330 const timeOptions = {
2431 format : timeFormat ,
@@ -39,20 +46,24 @@ export default class PrintableItinerary extends Component {
3946 { itinerary . legs . map ( ( leg , k ) => leg . transitLeg
4047 ? < TransitLeg
4148 key = { k }
42- leg = { leg }
49+ customIcons = { customIcons }
4350 interlineFollows = { k < itinerary . legs . length - 1 &&
4451 itinerary . legs [ k + 1 ] . interlineWithPreviousLeg
4552 }
53+ leg = { leg }
4654 timeOptions = { timeOptions } />
4755 : leg . hailedCar
4856 ? < TNCLeg
57+ customIcons = { customIcons }
4958 leg = { leg }
5059 timeOptions = { timeOptions } />
5160 : < AccessLeg
5261 key = { k }
62+ configCompanies = { configCompanies }
63+ customIcons = { customIcons }
5364 leg = { leg }
5465 timeOptions = { timeOptions }
55- companies = { companies } />
66+ />
5667 ) }
5768 < TripDetails itinerary = { itinerary } />
5869 </ div >
@@ -66,7 +77,7 @@ class TransitLeg extends Component {
6677 }
6778
6879 render ( ) {
69- const { leg, interlineFollows, timeOptions } = this . props
80+ const { customIcons , leg, interlineFollows, timeOptions } = this . props
7081
7182 // Handle case of transit leg interlined w/ previous
7283 if ( leg . interlineWithPreviousLeg ) {
@@ -91,7 +102,7 @@ class TransitLeg extends Component {
91102
92103 return (
93104 < div className = 'leg' >
94- < div className = 'mode-icon' > < ModeIcon mode = { leg . mode } /> </ div >
105+ < div className = 'mode-icon' > { getLegIcon ( leg , customIcons ) } </ div >
95106 < div className = 'leg-body' >
96107 < div className = 'leg-header' >
97108 < b > { leg . routeShortName } { leg . routeLongName } </ b > to < b > { leg . to . name } </ b >
@@ -123,14 +134,41 @@ class AccessLeg extends Component {
123134 }
124135
125136 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+
127162 return (
128163 < div className = 'leg' >
129- < div className = 'mode-icon' > < ModeIcon mode = { leg . mode } /> </ div >
164+ < div className = 'mode-icon' > { getLegIcon ( leg , customIcons ) } </ div >
130165 < div className = 'leg-body' >
131166 < 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 >
134172 </ div >
135173 { ! leg . hailedCar && (
136174 < div className = 'leg-details' >
@@ -155,13 +193,13 @@ class TNCLeg extends Component {
155193 }
156194
157195 render ( ) {
158- const { leg } = this . props
196+ const { customIcons , leg } = this . props
159197 const { tncData } = leg
160198 if ( ! tncData ) return null
161199
162200 return (
163201 < div className = 'leg' >
164- < div className = 'mode-icon' > < ModeIcon mode = { leg . mode } /> </ div >
202+ < div className = 'mode-icon' > { getLegIcon ( leg , customIcons ) } </ div >
165203 < div className = 'leg-body' >
166204 < div className = 'leg-header' >
167205 < b > Take { tncData . displayName } </ b > to < b > { leg . to . name } </ b >
0 commit comments