Allow departure-only / arrival-only online-board search submits

Previously handleRouteSubmit required both fields and returned silently
when only one was filled. Angular's
OnlineBoardUrlBuilderService.getRoutePageUrl switches on which side is
populated, routing to /onlineboard/departure/{dep}-{date} or
/onlineboard/arrival/{arr}-{date} for one-sided searches. React now
mirrors the same branch and only no-ops when neither side is filled
(matching Angular's `if (!departure && !arrival) return;` in
OnlineBoardFilterService.toRoutePage).
This commit is contained in:
2026-04-20 11:53:36 +03:00
parent 0c1701086d
commit 37ebda8455
@@ -197,11 +197,25 @@ export const OnlineBoardFilter: FC<OnlineBoardFilterProps> = ({
(e: FormEvent) => {
e.preventDefault();
// Mirrors Angular's OnlineBoardFilterService.toRoutePage + the
// UrlBuilder.getRoutePageUrl switch: one-sided searches (only
// departure or only arrival) route to /departure/ or /arrival/
// respectively; both sides route to /route/. No-op only when
// neither side is filled (Angular's
// `if (!departure && !arrival) return;`).
const dateParam = dateToYyyymmdd(routeDate ?? new Date());
const depCode = routeDepartureCode.trim().toUpperCase();
const arrCode = routeArrivalCode.trim().toUpperCase();
if (!depCode || !arrCode) return;
const url = buildOnlineBoardUrl({ type: "route", departure: depCode, arrival: arrCode, date: dateParam });
if (!depCode && !arrCode) return;
let url: string;
if (depCode && !arrCode) {
url = buildOnlineBoardUrl({ type: "departure", station: depCode, date: dateParam });
} else if (!depCode && arrCode) {
url = buildOnlineBoardUrl({ type: "arrival", station: arrCode, date: dateParam });
} else {
url = buildOnlineBoardUrl({ type: "route", departure: depCode, arrival: arrCode, date: dateParam });
}
void navigate(`/${locale}/${url}`);
},
[routeDepartureCode, routeArrivalCode, routeDate, navigate, locale],