fix(flight-live): keep a past flight's times in its booking view

The booking dialog and the phone sheet hid their departure and arrival tiles
as soon as the store held any leg of the flight, but a leg long over or never
seen by the feed draws no live card, so such a flight showed no times at
all. Both views now hide the tiles only for legs that get a card.
This commit is contained in:
Maurice
2026-11-16 10:45:23 +01:00
parent ea5542f8eb
commit 856d1e5ea5
7 changed files with 99 additions and 10 deletions
@@ -83,6 +83,8 @@ function delayText(minutes: number | null, t: T): { text: string; tone: DelayTon
/** The stages a card speaks for; without live data (past, unknown) there is no card. */
type ShownStage = Exclude<FlightStage, 'past' | 'unknown'>;
const isShown = (stage: FlightStage): stage is ShownStage => stage !== 'past' && stage !== 'unknown';
function headlineOf(
stage: ShownStage,
view: FlightLiveView,
@@ -193,7 +195,7 @@ export function useFlightLiveCard(tripId: number, reservationId: number, legInde
const view = flightLiveView(leg, now);
// No live data to show: the flight is long over, or the feed never heard it. Nothing at all then.
if (view.stage === 'past' || view.stage === 'unknown') return null;
if (!isShown(view.stage)) return null;
const time = (ms: number, tz: string | null) => airportTime(ms, tz, locale, timeFormat);
const { headline, detail } = headlineOf(view.stage, view, leg, t, time);
return {
@@ -214,6 +216,19 @@ export function useFlightLiveCard(tripId: number, reservationId: number, legInde
};
}
/**
* The legs of one booking a live card is drawn for, in leg order. The server
* hands over every followed leg at any date, but a flight long over or never
* heard by the feed gets no card (see useFlightLiveCard). The booking views
* hide their own time tiles only for these, so such a flight keeps its times.
*/
export function useFlightLiveCardLegs(tripId: number, reservationId: number): FlightLiveLeg[] {
const legs = useFlightLiveLegs(tripId, reservationId);
// The card's own pace, so a leg drops out here about when its card goes.
const now = useNow(30_000, legs.length > 0);
return legs.filter((leg) => isShown(flightLiveView(leg, now).stage));
}
/**
* The leg a one-line summary of a booking speaks for (see currentLeg), as a
* leg index, or null while TREK follows none of its legs.