mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 22:27:32 +00:00
fix(client): keep the seat change clear of the sheet's held ref and of non-null assertions
Client lint was red: passing the ref-held reservation to bookingSeats added a react-hooks/refs warning in MTransportSheet, so the sheet now reads the seats from the legs it already has (seatsOfLegs). The new PDF test used a non-null assertion.
This commit is contained in:
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user