diff --git a/src/features/schedule/components/ScheduleFlightBody.tsx b/src/features/schedule/components/ScheduleFlightBody.tsx index ec496805..32bd5655 100644 --- a/src/features/schedule/components/ScheduleFlightBody.tsx +++ b/src/features/schedule/components/ScheduleFlightBody.tsx @@ -52,8 +52,8 @@ function formatDuration(value: string | undefined, language: string): string { let m = 0; const hms = /^(\d+):(\d+):(\d+)$/.exec(value); if (hms) { - h = parseInt(hms[1]!, 10); - m = parseInt(hms[2]!, 10); + h = parseInt(hms[1] ?? "0", 10); + m = parseInt(hms[2] ?? "0", 10); } else { const iso = /^PT(?:(\d+)H)?(?:(\d+)M)?/.exec(value); if (iso) { @@ -145,11 +145,15 @@ export const ScheduleFlightBody: FC = ({ scheduled={leg.arrival.times.scheduledArrival.local} /> - {i < legs.length - 1 && ( - - {formatDuration(transferDuration(leg, legs[i + 1]!), language)} - - )} + {(() => { + const next = legs[i + 1]; + if (!next) return null; + return ( + + {formatDuration(transferDuration(leg, next), language)} + + ); + })()} ))} @@ -171,21 +175,25 @@ export const ScheduleFlightBody: FC = ({ )} ))} - - - {legs[legs.length - 1]!.arrival.scheduled.city} - - {legs[legs.length - 1]!.arrival.terminal && ( - - {[ - legs[legs.length - 1]!.arrival.scheduled.airport, - legs[legs.length - 1]!.arrival.terminal, - ] - .filter(Boolean) - .join(" - ")} + {(() => { + const lastLeg = legs[legs.length - 1]; + if (!lastLeg) return null; + const arrival = lastLeg.arrival; + return ( + + + {arrival.scheduled.city} + + {arrival.terminal && ( + + {[arrival.scheduled.airport, arrival.terminal] + .filter(Boolean) + .join(" - ")} + + )} - )} - + ); + })()} )} diff --git a/src/ui/city-autocomplete/CityPickerPopup.tsx b/src/ui/city-autocomplete/CityPickerPopup.tsx index f227d786..b19eeeb8 100644 --- a/src/ui/city-autocomplete/CityPickerPopup.tsx +++ b/src/ui/city-autocomplete/CityPickerPopup.tsx @@ -49,6 +49,9 @@ export const CityPickerPopup: FC = ({ {rows.map((row, idx) => { const rowKey = `${row.countryName ?? ""}-${row.city1?.code ?? ""}-${idx}`; const isMulti = Boolean(row.city1Airports); + const city1 = row.city1; + const city2 = row.city2; + const city1Airports = row.city1Airports; return (
= ({
{row.countryName ?? ""}
- {!isMulti && row.city1 && ( + {!isMulti && city1 && ( <>
onSelect(row.city1!.code)} + onClick={() => onSelect(city1.code)} onKeyDown={(e) => { - if (e.key === "Enter" || e.key === " ") onSelect(row.city1!.code); + if (e.key === "Enter" || e.key === " ") onSelect(city1.code); }} > - {row.city1.name} + {city1.name}
-
- {row.city2 && ( +
+ {city2 && (
onSelect(row.city2!.code)} + data-testid={`city-name-cell-${city2.name}`} + onClick={() => onSelect(city2.code)} onKeyDown={(e) => { - if (e.key === "Enter" || e.key === " ") onSelect(row.city2!.code); + if (e.key === "Enter" || e.key === " ") onSelect(city2.code); }} > - {row.city2.name} + {city2.name}
)}
)} - {isMulti && row.city1 && ( -
+ {isMulti && city1 && city1Airports && ( +
onSelect(row.city1!.code)} + data-testid={`city-name-cell-${city1.name}`} + onClick={() => onSelect(city1.code)} onKeyDown={(e) => { - if (e.key === "Enter" || e.key === " ") onSelect(row.city1!.code); + if (e.key === "Enter" || e.key === " ") onSelect(city1.code); }} > - {row.city1.name} + {city1.name}
- {row.city1Airports!.map((ap: IAirport) => ( + {city1Airports.map((ap: IAirport) => (