Skip to content

Commit

Permalink
feat: adds maximum interchange wait time to details page. Fixes #18410 (
Browse files Browse the repository at this point in the history
#305)

* feat: adds maximum interchange wait time to details page. Fixes #18410

* fix: support negative numbers
  • Loading branch information
mikaelbr authored Jun 25, 2024
1 parent ef18b93 commit c9d7bc3
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/page-modules/assistant/details/trip-section/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export default function TripSection({
<InterchangeSection
interchangeDetails={interchangeDetails}
publicCode={leg.line?.publicCode}
maximumWaitTime={leg.interchangeTo?.maximumWaitTime}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getPlaceName } from '../utils';
import { PageText, useTranslation } from '@atb/translations';

import style from './trip-section.module.css';
import { secondsToDuration } from '@atb/utils/date';

export type InterchangeDetails = {
publicCode: string;
Expand All @@ -16,46 +17,70 @@ export type InterchangeDetails = {
export type InterchangeSectionProps = {
interchangeDetails: InterchangeDetails;
publicCode?: string | null;
maximumWaitTime?: number;
};

export function InterchangeSection({
interchangeDetails,
publicCode,
}: InterchangeSectionProps) {
export function InterchangeSection(props: InterchangeSectionProps) {
const { t } = useTranslation();
const unknownTransportationColor = useTransportationThemeColor({
transportMode: 'unknown',
transportSubModes: undefined,
});

const message = useInterchangeTextTranslation(props);

return (
<div className={style.rowContainer}>
<DecorationLine color={unknownTransportationColor.backgroundColor} />
<TripRow rowLabel={<MonoIcon icon="actions/Interchange" />}>
<MessageBox
noStatusIcon
type="info"
message={
publicCode
? t(
PageText.Assistant.details.tripSection.interchange(
publicCode,
interchangeDetails.publicCode,
interchangeDetails.fromPlace,
),
)
: t(
PageText.Assistant.details.tripSection.interchangeWithUnknownFromPublicCode(
interchangeDetails.publicCode,
interchangeDetails.fromPlace,
),
)
}
/>
<MessageBox noStatusIcon type="info" message={message} />
</TripRow>
</div>
);
}

function useInterchangeTextTranslation({
publicCode,
interchangeDetails,
maximumWaitTime = 0,
}: InterchangeSectionProps) {
const { t, language } = useTranslation();

// If maximum wait time is defined or over 0, append it to the message.
const appendWaitTime = (text: string) =>
maximumWaitTime > 0
? [
text,
t(
PageText.Assistant.details.tripSection.interchangeMaxWait(
secondsToDuration(maximumWaitTime, language),
),
),
].join(' ')
: text;

if (publicCode) {
return appendWaitTime(
t(
PageText.Assistant.details.tripSection.interchange(
publicCode,
interchangeDetails.publicCode,
interchangeDetails.fromPlace,
),
),
);
}

return appendWaitTime(
t(
PageText.Assistant.details.tripSection.interchangeWithUnknownFromPublicCode(
interchangeDetails.publicCode,
interchangeDetails.fromPlace,
),
),
);
}

export function getInterchangeDetails(
legs: TripPatternWithDetails['legs'],
id: string | undefined,
Expand Down
1 change: 1 addition & 0 deletions src/page-modules/assistant/server/journey-planner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ export function createJourneyApi(
interchangeTo: leg.interchangeTo?.toServiceJourney?.id
? {
guaranteed: leg.interchangeTo.guaranteed ?? false,
maximumWaitTime: leg.interchangeTo.maximumWaitTime ?? 0,
toServiceJourney: {
id: leg.interchangeTo.toServiceJourney.id,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ query TripsWithDetails(
}
interchangeTo {
guaranteed
maximumWaitTime
toServiceJourney {
id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ query ViaTripsWithDetails(
}
interchangeTo {
guaranteed
maximumWaitTime
toServiceJourney {
id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export const tripPatternWithDetailsSchema = z.object({
interchangeTo: z
.object({
guaranteed: z.boolean(),
maximumWaitTime: z.number(),
toServiceJourney: z.object({ id: z.string() }),
})
.nullable(),
Expand Down
6 changes: 6 additions & 0 deletions src/translations/pages/assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ const AssistantInternal = {
`Correspondance with ${toPublicCode} on ${location}.`,
`Korrespondanse med ${toPublicCode}${location}.`,
),
interchangeMaxWait: (maxWaitTime: string) =>
_(
`Venter inntil ${maxWaitTime}.`,
`Waiting up to ${maxWaitTime}.`,
`Ventar i opp til ${maxWaitTime}.`,
),
wait: {
label: (time: string) =>
_(`Vent i ${time}`, `Wait for ${time}`, `Vent i ${time}`),
Expand Down

0 comments on commit c9d7bc3

Please sign in to comment.