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-6654: Combine walk and wait cards #5231

Merged
merged 7 commits into from
Jan 23, 2025
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
55 changes: 55 additions & 0 deletions app/component/itinerary/navigator/NaviBoardingInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import RouteNumberContainer from '../../RouteNumberContainer';
import { routeShape } from '../../../util/shapes';
import Icon from '../../Icon';

const NaviBoardingInfo = ({
route,
mode,
headsign,
translationValues,
withExpandIcon,
}) => {
return (
<div className={cx('boarding', withExpandIcon && 'with-icon')}>
<div className="route-info">
{withExpandIcon && (
<Icon img="navi-expand" className="icon-expand-small" />
)}
<RouteNumberContainer
className={cx('line', mode)}
route={route}
mode={mode}
isTransitLeg
vertical
withBar
/>
<div className="headsign">{headsign}</div>
</div>
<div className="wait-duration">
<FormattedMessage
id="navileg-departing-at"
defaultMessage="{duration} min päästä klo {legTime}"
values={translationValues}
/>
</div>
</div>
);
};

NaviBoardingInfo.propTypes = {
route: routeShape.isRequired,
mode: PropTypes.string.isRequired,
headsign: PropTypes.string.isRequired,
// eslint-disable-next-line react/forbid-prop-types
translationValues: PropTypes.object.isRequired,
withExpandIcon: PropTypes.bool,
};
NaviBoardingInfo.defaultProps = {
withExpandIcon: false,
};

export default NaviBoardingInfo;
7 changes: 6 additions & 1 deletion app/component/itinerary/navigator/NaviCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ export default function NaviCard(
<div className="main-card">
<div className="content">{mainCardContent}</div>
{cardExpanded && (
<NaviCardExtension legType={legType} leg={leg} nextLeg={nextLeg} />
<NaviCardExtension
legType={legType}
leg={leg}
nextLeg={nextLeg}
time={time}
/>
)}
</div>
);
Expand Down
44 changes: 37 additions & 7 deletions app/component/itinerary/navigator/NaviCardExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import PlatformNumber from '../../PlatformNumber';
import {
getZoneLabel,
getHeadsignFromRouteLongName,
legTime,
legTimeStr,
} from '../../../util/legUtils';
import ZoneIcon from '../../ZoneIcon';
import { legShape, configShape } from '../../../util/shapes';
import { getDestinationProperties, LEGTYPE } from './NaviUtils';
import { getDestinationProperties, LEGTYPE, withRealTime } from './NaviUtils';
import { getRouteMode } from '../../../util/modeUtils';

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

const NaviCardExtension = ({ legType, leg, nextLeg }, { config }) => {
const NaviCardExtension = ({ legType, leg, nextLeg, time }, { config }) => {
const { stop, name, rentalVehicle, vehicleParking, vehicleRentalStation } =
leg ? leg.to : nextLeg.from;
const { code, platformCode, zoneId, vehicleMode } = stop || {};
Expand Down Expand Up @@ -73,10 +75,10 @@ const NaviCardExtension = ({ legType, leg, nextLeg }, { config }) => {
</div>
);
}
const stopInformation = () => {
const stopInformation = (expandIcon = false) => {
return (
<div className="extension-walk">
<Icon img="navi-expand" className="icon-expand" />
{expandIcon && <Icon img="navi-expand" className="icon-expand" />}
<Icon
img={destination.iconId}
height={2}
Expand Down Expand Up @@ -125,22 +127,50 @@ const NaviCardExtension = ({ legType, leg, nextLeg }, { config }) => {
}}
/>
</div>
{stopInformation(true)}
</div>
);
}
if (legType === LEGTYPE.MOVE && nextLeg?.transitLeg) {
const { headsign, route, start } = nextLeg;
const hs = headsign || nextLeg.trip?.tripHeadsign;
const remainingDuration = Math.max(
Math.ceil((legTime(start) - time) / 60000),
0,
); // ms to minutes, >= 0
const rt = nextLeg.realtimeState === 'UPDATED';
const values = {
duration: withRealTime(rt, remainingDuration),
legTime: withRealTime(rt, legTimeStr(start)),
};
const routeMode = getRouteMode(route, config);
return (
<div className={cx('extension', 'no-gap')}>
{stopInformation()}
<div className="extension-divider" />
<NaviBoardingInfo
route={route}
mode={routeMode}
headsign={hs}
translationValues={values}
withExpandIcon
/>
</div>
);
}

return (
<div className="extension">
<div className="extension-divider" />
{stopInformation()}
{stopInformation(true)}
</div>
);
};

NaviCardExtension.propTypes = {
leg: legShape,
nextLeg: legShape,
legType: PropTypes.string,
time: PropTypes.number.isRequired,
};

NaviCardExtension.defaultProps = {
Expand Down
49 changes: 18 additions & 31 deletions app/component/itinerary/navigator/NaviInstructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,31 @@ import cx from 'classnames';
import { displayDistance } from '../../../util/geo-utils';
import { legShape, configShape } from '../../../util/shapes';
import { legDestination, legTimeStr, legTime } from '../../../util/legUtils';
import RouteNumber from '../../RouteNumber';
import { LEGTYPE, getLocalizedMode, getToLocalizedMode } from './NaviUtils';
import {
LEGTYPE,
getLocalizedMode,
getToLocalizedMode,
withRealTime,
} from './NaviUtils';
import { durationToString } from '../../../util/timeUtils';
import { getRouteMode } from '../../../util/modeUtils';
import NaviBoardingInfo from './NaviBoardingInfo';

export default function NaviInstructions(
{ leg, nextLeg, instructions, legType, time, position, tailLength },
{ intl, config },
) {
const withRealTime = (rt, children) => (
<span className={cx('bold', { realtime: rt })}>{children}</span>
);

if (legType === LEGTYPE.MOVE) {
return (
<>
<div className="notification-header">
<FormattedMessage id={instructions} defaultMessage="Go to" />
&nbsp;
{legDestination(intl, leg, null, nextLeg)}
&nbsp;
{nextLeg?.transitLeg && (
<FormattedMessage id="navileg-hop-on" defaultMessage="by" />
)}
</div>

<div className={cx('duration', { realtime: !!position })}>
Expand All @@ -34,7 +39,7 @@ export default function NaviInstructions(
</>
);
}
if (legType === LEGTYPE.WAIT && nextLeg.transitLeg) {
if (legType === LEGTYPE.WAIT && nextLeg?.transitLeg) {
const { mode, headsign, route, start } = nextLeg;
const hs = headsign || nextLeg.trip?.tripHeadsign;

Expand All @@ -48,11 +53,6 @@ export default function NaviInstructions(
legTime: withRealTime(rt, legTimeStr(start)),
};
const routeMode = getRouteMode(route, config);
const iconColor =
config.colors.iconColors[`mode-${routeMode}`] ||
route.color ||
'currentColor';

return (
<>
<div className="notification-header">
Expand All @@ -62,25 +62,12 @@ export default function NaviInstructions(
defaultMessage="Get on the {mode}"
/>
</div>
<div className="wait-leg">
<div className="route-info">
<RouteNumber
mode={routeMode}
text={route?.shortName}
withBar
isTransitLeg
color={iconColor}
/>
<div className="headsign">{hs}</div>
</div>
<div className="wait-duration">
<FormattedMessage
id="navileg-arrive-at"
defaultMessage="{duration} min päästä klo {legTime}"
values={values}
/>
</div>
</div>
<NaviBoardingInfo
route={route}
mode={routeMode}
headsign={hs}
translationValues={values}
/>
</>
);
}
Expand Down
7 changes: 6 additions & 1 deletion app/component/itinerary/navigator/NaviUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import distance from '@digitransit-search-util/digitransit-search-util-distance';
import React from 'react';
import cx from 'classnames';
import { FormattedMessage } from 'react-intl';
import { ExtendedRouteTypes } from '../../../constants';
import { getFaresFromLegs, formatFare } from '../../../util/fareUtils';
Expand Down Expand Up @@ -252,7 +253,7 @@ export const getAdditionalMessages = (
) {
// Todo: multiple fares?
const fares = getFaresFromLegs([nextLeg], config);
if (fares?.length) {
if (fares?.length && !fares[0].isUnknown) {
msgs.push({
severity: 'INFO',
content: (
Expand Down Expand Up @@ -650,3 +651,7 @@ export const LEGTYPE = {
END: 'END',
WAIT_IN_VEHICLE: 'WAIT_IN_VEHICLE',
};

export const withRealTime = (rt, children) => (
<span className={cx('bold', { realtime: rt })}>{children}</span>
);
Loading
Loading