Skip to content

Commit

Permalink
fix(RouteViewer): fix 'disappearing' routes on click
Browse files Browse the repository at this point in the history
fix #130
  • Loading branch information
landonreed committed Feb 18, 2020
1 parent 3b7694a commit 599fd68
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/components/viewers/route-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class RouteViewer extends Component {
<RouteRow
findRoute={findRoute}
isActive={viewedRoute && viewedRoute.routeId === route.id}
key={route.id
/* operator={operator */}
key={route.id}
// operator={operator}
route={route}
setViewedRoute={setViewedRoute}
/>
Expand Down
61 changes: 42 additions & 19 deletions lib/util/itinerary.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,29 +262,52 @@ function getSortValues (getterFn, a, b) {
return { aVal, bVal }
}

/**
* Lookup for the sort values associated with various OTP modes.
*/
const modeComparatorValue = {
SUBWAY: 1,
TRAM: 2,
RAIL: 3,
GONDOLA: 4,
FERRY: 5,
CABLE_CAR: 6,
FUNICULAR: 7,
BUS: 8
}

/**
* Lookup that maps route types to the OTP mode sort values.
*/
const routeTypeComparatorValue = {
0: modeComparatorValue.TRAM, // - Tram, Streetcar, Light rail.
1: modeComparatorValue.SUBWAY, // - Subway, Metro.
2: modeComparatorValue.RAIL, // - Rail. Used for intercity or long-distance travel.
3: modeComparatorValue.BUS, // - Bus.
4: modeComparatorValue.FERRY, // - Ferry.
5: modeComparatorValue.CABLE_CAR, // - Cable tram.
6: modeComparatorValue.GONDOLA, // - Gondola, etc.
7: modeComparatorValue.FUNICULAR, // - Funicular.
// TODO: 11 and 12 are not a part of OTP as of 2019-02-14, but for now just
// associate them with bus/rail.
11: modeComparatorValue.BUS, // - Trolleybus.
12: modeComparatorValue.RAIL // - Monorail.
}

/**
* Gets a comparator value for a given route's type (OTP mode).
*/
function getRouteTypeComparatorValue (route) {
switch (route.mode) {
case 'SUBWAY':
return 1
case 'TRAM':
return 2
case 'RAIL':
return 3
case 'GONDOLA':
return 4
case 'FERRY':
return 5
case 'CABLE_CAR':
return 6
case 'FUNICULAR':
return 7
case 'BUS':
return 8
default:
return 9999
// For some strange reason, the short route response in OTP returns the
// string-based modes, but the long route response returns the
// integer route type. This attempts to account for both of those cases.
if (typeof route.mode !== 'undefined') {
return modeComparatorValue[route.mode]
} else if (typeof route.type !== 'undefined') {
return routeTypeComparatorValue[route.type]
} else {
console.warn('no mode/route type found for route', route)
return 9999
}
}

Expand Down

0 comments on commit 599fd68

Please sign in to comment.