diff --git a/src/features/online-board/components/OnlineBoardFilter.tsx b/src/features/online-board/components/OnlineBoardFilter.tsx index b3ead5b7..98d9e3e8 100644 --- a/src/features/online-board/components/OnlineBoardFilter.tsx +++ b/src/features/online-board/components/OnlineBoardFilter.tsx @@ -61,6 +61,15 @@ function yyyymmddToDate(yyyymmdd: string): Date { return new Date(y, m, d); } +function isSameLocalDay(a: Date | null, b: Date | null): boolean { + if (!a || !b) return false; + return ( + a.getFullYear() === b.getFullYear() && + a.getMonth() === b.getMonth() && + a.getDate() === b.getDate() + ); +} + export const OnlineBoardFilter: FC = ({ initialDeparture, initialArrival, @@ -91,6 +100,24 @@ export const OnlineBoardFilter: FC = ({ ); const [timeRange, setTimeRange] = useState<[number, number]>([0, 1440]); + // Swap the Calendar input's display text to the translated 'Сегодня' + // label when the selected date is today — Angular ships this in its + // date field and the raw 'DD.MM.YYYY' reads clinical in comparison. + const flightDateInputRef = useRef(null); + const routeDateInputRef = useRef(null); + const todayLabel = t("SHARED.TODAY"); + useEffect(() => { + const today = new Date(); + const apply = (ref: HTMLInputElement | null, date: Date | null) => { + if (!ref) return; + if (isSameLocalDay(date, today)) { + ref.value = todayLabel; + } + }; + apply(flightDateInputRef.current, flightDate); + apply(routeDateInputRef.current, routeDate); + }, [flightDate, routeDate, todayLabel, activeTab]); + // When the parent feeds new initial* props (e.g. a popular-request click // pushes ?departure=SVO&arrival=LED into the URL), keep the fields in // sync. useState only reads initial values once, so without this effect @@ -256,6 +283,7 @@ export const OnlineBoardFilter: FC = ({ className="input--filter" data-testid="date-input" inputId="search-date-input" + inputRef={flightDateInputRef} /> @@ -344,6 +372,7 @@ export const OnlineBoardFilter: FC = ({ className="input--filter" data-testid="date-input" inputId="route-date-input" + inputRef={routeDateInputRef} />