Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DT-6599:Add support for ExtendedRouteType colors #5196

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/component/itinerary/PlanConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const planConnection = graphql`
color
gtfsId
type
mode
agency {
name
}
Expand Down
36 changes: 22 additions & 14 deletions app/component/itinerary/navigator/NaviCard.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from 'react';
import { FormattedMessage } from 'react-intl';
import PropTypes from 'prop-types';
import { legShape } from '../../../util/shapes';
import { legShape, configShape } from '../../../util/shapes';
import Icon from '../../Icon';
import { isRental } from '../../../util/legUtils';
import NaviInstructions from './NaviInstructions';
import NaviCardExtension from './NaviCardExtension';
import { LEGTYPE } from './NaviUtils';
import { getRouteMode } from '../../../util/modeUtils';

const iconMap = {
BICYCLE: 'icon-icon_cyclist',
Expand All @@ -19,18 +20,15 @@ const iconMap = {
SUBWAY: 'icon-icon_subway',
TRAM: 'icon-icon_tram',
FERRY: 'icon-icon_ferry',
'BUS-EXPRESS': 'icon-icon_bus-express',
'BUS-LOCAL': 'icon-icon_bus-local',
SPEEDTRAM: 'icon-icon_speedtram',
};

export default function NaviCard({
leg,
nextLeg,
legType,
cardExpanded,
startTime,
time,
position,
origin,
}) {
export default function NaviCard(
{ leg, nextLeg, legType, cardExpanded, startTime, time, position, origin },
{ config },
) {
if (legType === LEGTYPE.PENDING) {
return (
<FormattedMessage
Expand All @@ -45,25 +43,31 @@ export default function NaviCard({
if (!leg && !nextLeg) {
return null;
}
const iconName = legType === LEGTYPE.WAIT ? iconMap.WAIT : iconMap[leg.mode];

let iconColor = 'currentColor';
let iconName;
let instructions = '';
if (legType === LEGTYPE.TRANSIT) {
const m = getRouteMode(leg.route, config);
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()}`;
iconName = iconMap.WALK;
}

return (
<div className="navi-top-card">
<div className="main-card">
<Icon img={iconName} className="mode" />
<Icon img={iconName} className="mode" color={iconColor} />
<div className={`instructions ${cardExpanded ? 'expanded' : ''}`}>
<NaviInstructions
leg={leg}
Expand Down Expand Up @@ -117,3 +121,7 @@ NaviCard.defaultProps = {
startTime: '',
position: undefined,
};

NaviCard.contextTypes = {
config: configShape.isRequired,
};
6 changes: 4 additions & 2 deletions app/component/itinerary/navigator/NaviCardExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getZoneLabel, legTime } from '../../../util/legUtils';
import ZoneIcon from '../../ZoneIcon';
import { legShape, configShape } from '../../../util/shapes';
import { getDestinationProperties, LEGTYPE } from './NaviUtils';
import { getRouteMode } from '../../../util/modeUtils';

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

Expand All @@ -34,7 +35,7 @@ const NaviCardExtension = ({ legType, leg, nextLeg, time }, { config }) => {
}

if (legType === LEGTYPE.TRANSIT) {
const { intermediatePlaces, headsign, trip, realtimeState } = leg;
const { intermediatePlaces, headsign, trip, realtimeState, route } = leg;
const hs = headsign || trip.tripHeadsign;
const idx = intermediatePlaces.findIndex(p => legTime(p.arrival) > time);
const count = idx > -1 ? intermediatePlaces.length - idx : 0;
Expand All @@ -45,7 +46,8 @@ const NaviCardExtension = ({ legType, leg, nextLeg, time }, { config }) => {
);
const translationId =
count === 1 ? 'navileg-one-stop-remaining' : 'navileg-stops-remaining';
const mode = leg.mode.toLowerCase();
const mode = getRouteMode(route, config);

return (
<div className="extension">
<div className="extension-divider" />
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);
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
1 change: 1 addition & 0 deletions app/component/itinerary/navigator/NaviUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const getAdditionalMessages = (leg, time, intl, config, messages) => {
return msgs;
};

// TODO: DATA SHOULD BE UPDATED
export const getTransitLegState = (leg, intl, messages, time) => {
const { start, realtimeState, from, mode, legId, route, end } = leg;
const { scheduledTime, estimated } = start;
Expand Down
8 changes: 8 additions & 0 deletions app/component/itinerary/navigator/navigator.scss
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@
color: $bus-color;
}

&.bus-express {
color: $bus-express-color;
}

&.speedtram {
color: $speedtram-color;
}

&.tram-stop {
color: $tram-color;
}
Expand Down
Loading