Drop 14 non-null assertions in ScheduleFlightBody + CityPickerPopup
- ScheduleFlightBody.tsx: hms regex capture uses `?? "0"` fallback; inline IIFEs expose last-leg and transfer-to-next in narrowed scope. - CityPickerPopup.tsx: row.city1/city2/city1Airports are lifted into locals so the narrowing survives into JSX event handler closures. Warning count: 55 → 41.
This commit is contained in:
@@ -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<ScheduleFlightBodyProps> = ({
|
||||
scheduled={leg.arrival.times.scheduledArrival.local}
|
||||
/>
|
||||
</span>
|
||||
{i < legs.length - 1 && (
|
||||
<span className="schedule-flight-body__timeline-transit">
|
||||
{formatDuration(transferDuration(leg, legs[i + 1]!), language)}
|
||||
</span>
|
||||
)}
|
||||
{(() => {
|
||||
const next = legs[i + 1];
|
||||
if (!next) return null;
|
||||
return (
|
||||
<span className="schedule-flight-body__timeline-transit">
|
||||
{formatDuration(transferDuration(leg, next), language)}
|
||||
</span>
|
||||
);
|
||||
})()}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
@@ -171,21 +175,25 @@ export const ScheduleFlightBody: FC<ScheduleFlightBodyProps> = ({
|
||||
)}
|
||||
</span>
|
||||
))}
|
||||
<span className="schedule-flight-body__timeline-station">
|
||||
<span className="schedule-flight-body__timeline-station-city">
|
||||
{legs[legs.length - 1]!.arrival.scheduled.city}
|
||||
</span>
|
||||
{legs[legs.length - 1]!.arrival.terminal && (
|
||||
<span className="schedule-flight-body__timeline-station-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 (
|
||||
<span className="schedule-flight-body__timeline-station">
|
||||
<span className="schedule-flight-body__timeline-station-city">
|
||||
{arrival.scheduled.city}
|
||||
</span>
|
||||
{arrival.terminal && (
|
||||
<span className="schedule-flight-body__timeline-station-terminal">
|
||||
{[arrival.scheduled.airport, arrival.terminal]
|
||||
.filter(Boolean)
|
||||
.join(" - ")}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
})()}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -49,6 +49,9 @@ export const CityPickerPopup: FC<CityPickerPopupProps> = ({
|
||||
{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 (
|
||||
<div
|
||||
key={rowKey}
|
||||
@@ -58,59 +61,59 @@ export const CityPickerPopup: FC<CityPickerPopupProps> = ({
|
||||
<div>{row.countryName ?? ""}</div>
|
||||
</div>
|
||||
|
||||
{!isMulti && row.city1 && (
|
||||
{!isMulti && city1 && (
|
||||
<>
|
||||
<div
|
||||
className={`cell city${row.city1.code === selectedCode ? " city-active" : ""}`}
|
||||
data-testid={`city-name-cell-${row.city1.name}`}
|
||||
className={`cell city${city1.code === selectedCode ? " city-active" : ""}`}
|
||||
data-testid={`city-name-cell-${city1.name}`}
|
||||
>
|
||||
<div
|
||||
className="city--item"
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => 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}
|
||||
</div>
|
||||
</div>
|
||||
<div className={`cell city${row.city2?.code === selectedCode ? " city-active" : ""}`}>
|
||||
{row.city2 && (
|
||||
<div className={`cell city${city2?.code === selectedCode ? " city-active" : ""}`}>
|
||||
{city2 && (
|
||||
<div
|
||||
className="city--item"
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
data-testid={`city-name-cell-${row.city2.name}`}
|
||||
onClick={() => 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}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{isMulti && row.city1 && (
|
||||
<div className={`cell city${row.city1.code === selectedCode ? " city-active" : ""}`}>
|
||||
{isMulti && city1 && city1Airports && (
|
||||
<div className={`cell city${city1.code === selectedCode ? " city-active" : ""}`}>
|
||||
<div
|
||||
className="city--item"
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
data-testid={`city-name-cell-${row.city1.name}`}
|
||||
onClick={() => 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}
|
||||
</div>
|
||||
<div className="airports-column">
|
||||
{row.city1Airports!.map((ap: IAirport) => (
|
||||
{city1Airports.map((ap: IAirport) => (
|
||||
<div
|
||||
key={ap.code}
|
||||
title={ap.name}
|
||||
|
||||
Reference in New Issue
Block a user