Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(client): keep the seat change clear of the sheet's held ref and of non-null assertions

Maurice49b9ffc77d48
diff --git a/client/src/components/PDF/TripPDF.test.ts b/client/src/components/PDF/TripPDF.test.ts
index 25744102d..4859acb59 100644
--- a/client/src/components/PDF/TripPDF.test.ts
+++ b/client/src/components/PDF/TripPDF.test.ts
@@ -272,7 +272,7 @@ describe('downloadTripPDF', () => {
}),
}
await downloadTripPDF({ ...richArgs, reservations: [direct, stopover] })
- const html = getIframe()!.srcdoc
+ const html = getIframe()?.srcdoc ?? ''
expect(html).toContain('Air Italia · AI123 · reservations.meta.seat 31A · CDG → FCO')
expect(html).toContain('Lufthansa · LH2 · reservations.meta.seat 14C · BER → HND')
expect(html).not.toContain('LH1 · reservations.meta.seat')
diff --git a/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx b/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx
index e1dfd6928..945a16a80 100644
--- a/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx
+++ b/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx
@@ -7,7 +7,7 @@ import { useTranslation } from '../../../../i18n'
import { useSettingsStore } from '../../../../store/settingsStore'
import { RES_ICONS } from '../../../../components/Planner/DayPlanSidebar.constants'
import { splitReservationDateTime } from '../../../../utils/formatters'
-import { bookingSeats, getFlightLegs, getTrainLegs, seatLabel, usesStationRoute, type FlightLeg, type TrainLeg } from '../../../../utils/flightLegs'
+import { getFlightLegs, getTrainLegs, seatLabel, seatsOfLegs, usesStationRoute, type FlightLeg, type TrainLeg } from '../../../../utils/flightLegs'
import { runsOnDay } from '../../../../utils/reservationRoutes'
import { filesFor } from '../../../../utils/reservationFiles'
import { bookingDayLabel, segmentCodeLabel } from '../../../../components/Planner/transportDetailModel'
@@ -171,7 +171,7 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) {
// Opened from a leg, that leg's own seat; the whole booking lists the seat of
// every leg that has one, each under its route, rather than only the first's.
- const seats: { route: string | null; seat: string }[] = leg ? (legDetail.seat ? [{ route: null, seat: legDetail.seat }] : []) : bookingSeats(res)
+ const seats: { route: string | null; seat: string }[] = leg ? (legDetail.seat ? [{ route: null, seat: legDetail.seat }] : []) : seatsOfLegs(routeLegs, meta.seat)
const ownSeat = seats.find(s => s.route == null)?.seat
const legSeats = seats.filter(s => s.route != null)
// A flight's legs carry no platform of their own, so that stays the booking's.
diff --git a/client/src/utils/flightLegs.ts b/client/src/utils/flightLegs.ts
index cedd6b0c4..f9686833e 100644
--- a/client/src/utils/flightLegs.ts
+++ b/client/src/utils/flightLegs.ts
@@ -184,11 +184,15 @@ function legSeat(leg: { seat?: unknown } | null | undefined, index: number, meta
export function bookingSeats(r: Reservation): { route: string | null; seat: string }[] {
const legs: (FlightLeg | TrainLeg)[] =
r.type === 'flight' ? getFlightLegs(r) : usesStationRoute(r.type) ? getTrainLegs(r) : []
+ return seatsOfLegs(legs, parseReservationMetadata(r).seat)
+}
+
+/** bookingSeats for legs already read (getFlightLegs or getTrainLegs) and the booking's flat seat. */
+export function seatsOfLegs(legs: readonly (FlightLeg | TrainLeg)[], flatSeat: unknown): { route: string | null; seat: string }[] {
if (legs.length > 1) {
return legs.flatMap((l) => (l.seat ? [{ route: [l.from, l.to].filter(Boolean).join(' → ') || null, seat: l.seat }] : []))
}
- const seat = parseReservationMetadata(r).seat
- return typeof seat === 'string' && seat ? [{ route: null, seat }] : []
+ return typeof flatSeat === 'string' && flatSeat ? [{ route: null, seat: flatSeat }] : []
}
/** The label of one of bookingSeats' seats: "Seat", or "Seat FRA → IST" for a leg. */