Skip to content

Commit

Permalink
use modeutils to determine routemode
Browse files Browse the repository at this point in the history
  • Loading branch information
Antiik91 committed Dec 11, 2024
1 parent ab5f35b commit a8acbd9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
25 changes: 11 additions & 14 deletions app/component/itinerary/navigator/NaviCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isRental } from '../../../util/legUtils';
import NaviInstructions from './NaviInstructions';
import NaviCardExtension from './NaviCardExtension';
import { LEGTYPE } from './NaviUtils';
import { ExtendedRouteTypes } from '../../../constants';
import { getRouteMode } from '../../../util/modeUtils';

const iconMap = {
BICYCLE: 'icon-icon_cyclist',
Expand All @@ -20,8 +20,9 @@ const iconMap = {
SUBWAY: 'icon-icon_subway',
TRAM: 'icon-icon_tram',
FERRY: 'icon-icon_ferry',
BUS_EXPRESS: 'icon-icon_bus-express',
SPEED_TRAM: 'icon-icon_speed-tram',
'BUS-EXPRESS': 'icon-icon_bus-express',
'BUS-LOCAL': 'icon-icon_bus-local',
SPEEDTRAM: 'icon-icon_speedtram',
};

export default function NaviCard(
Expand All @@ -42,29 +43,25 @@ export default function NaviCard(
if (!leg && !nextLeg) {
return null;
}
let iconColor = 'currentColor';
let iconName;

let instructions = '';
if (legType === LEGTYPE.TRANSIT) {
const m = getRouteMode(leg.route, config) || leg.mode;
iconColor = config.colors.iconColors[`mode-${m}`] || leg.route.color;
iconName = iconMap[m.toUpperCase()];

instructions = `navileg-in-transit`;
} else if (legType !== LEGTYPE.WAIT && isRental(leg, nextLeg)) {
if (leg.mode === 'WALK' && nextLeg?.mode === 'SCOOTER') {
instructions = `navileg-rent-scooter`;
} else {
instructions = 'rent-cycle-at';
}
iconName = iconMap[leg.mode];
} else if (legType === LEGTYPE.MOVE) {
instructions = `navileg-${leg?.mode.toLowerCase()}`;
}
let iconColor = 'currentColor';
if (leg?.route?.type === ExtendedRouteTypes.BusExpress) {
iconColor = config.colors.iconColors['mode-bus-express'];
iconName = iconMap.BUS_EXPRESS;
} else if (leg?.route?.type === ExtendedRouteTypes.SpeedTram) {
iconColor = config.colors.iconColors['mode-speedtram'];
iconName = iconMap.SPEED_TRAM;
} else {
iconName = legType === LEGTYPE.WAIT ? iconMap.WAIT : iconMap[leg.mode];
iconName = iconMap.WALK;
}

return (
Expand Down
11 changes: 2 additions & 9 deletions app/component/itinerary/navigator/NaviCardExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getZoneLabel, legTime } from '../../../util/legUtils';
import ZoneIcon from '../../ZoneIcon';
import { legShape, configShape } from '../../../util/shapes';
import { getDestinationProperties, LEGTYPE } from './NaviUtils';
import { ExtendedRouteTypes } from '../../../constants';
import { getRouteMode } from '../../../util/modeUtils';

import RouteNumberContainer from '../../RouteNumberContainer';

Expand Down Expand Up @@ -46,14 +46,7 @@ const NaviCardExtension = ({ legType, leg, nextLeg, time }, { config }) => {
);
const translationId =
count === 1 ? 'navileg-one-stop-remaining' : 'navileg-stops-remaining';
let mode;
if (route.type === ExtendedRouteTypes.BusExpress) {
mode = 'bus-express';
} else if (route.type === ExtendedRouteTypes.SpeedTram) {
mode = 'speedtram';
} else {
mode = leg.mode.toLowerCase();
}
const mode = getRouteMode(route, config) || leg.mode;

return (
<div className="extension">
Expand Down
12 changes: 9 additions & 3 deletions app/component/itinerary/navigator/NaviInstructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { legDestination, legTimeStr, legTime } from '../../../util/legUtils';
import RouteNumber from '../../RouteNumber';
import { LEGTYPE, getLocalizedMode, pathProgress } from './NaviUtils';
import { durationToString } from '../../../util/timeUtils';
import { getRouteMode } from '../../../util/modeUtils';

export default function NaviInstructions(
{ leg, nextLeg, instructions, legType, time, position, origin },
Expand Down Expand Up @@ -50,7 +51,6 @@ export default function NaviInstructions(
if (legType === LEGTYPE.WAIT && nextLeg.mode !== 'WALK') {
const { mode, headsign, route, start } = nextLeg;
const hs = headsign || nextLeg.trip?.tripHeadsign;
const color = route.color || 'currentColor';
const localizedMode = getLocalizedMode(mode, intl);

const remainingDuration = Math.ceil((legTime(start) - time) / 60000); // ms to minutes
Expand All @@ -59,6 +59,12 @@ export default function NaviInstructions(
duration: withRealTime(rt, remainingDuration),
legTime: withRealTime(rt, legTimeStr(start)),
};
const routeMode = getRouteMode(route, config) || mode;
const iconColor =
config.colors.iconColors[`mode-${routeMode}`] ||
route.color ||
'currentColor';

return (
<>
<div className="destination-header">
Expand All @@ -71,11 +77,11 @@ export default function NaviInstructions(
<div className="wait-leg">
<div className="route-info">
<RouteNumber
mode={mode.toLowerCase()}
mode={routeMode}
text={route?.shortName}
withBar
isTransitLeg
color={color}
color={iconColor}
/>
<div className="headsign">{hs}</div>
</div>
Expand Down

0 comments on commit a8acbd9

Please sign in to comment.