- Introduced ServiceWindow component to display the last departure today and the first tomorrow. - Implemented cancellation notice parsing to handle route cancellations effectively. - Enhanced departure display logic to include cancellation alerts and status updates. - Created information blocks for displaying service information, weather, and QR codes. - Added tests for departure features, information handling, and service window functionality. - Updated fixtures for testing various scenarios including cancellations and long wait times.
23 lines
1.6 KiB
TypeScript
23 lines
1.6 KiB
TypeScript
import { NumericText } from './NumericText';
|
||
import { RouteBadge } from './RouteBadge';
|
||
import type { Departure } from './types';
|
||
|
||
export function ServiceWindow({ lastToday, firstTomorrow, available, tomorrowAvailable, loading, now }: {
|
||
lastToday: Departure | null; firstTomorrow: Departure | null; available: boolean;
|
||
tomorrowAvailable: boolean; loading: boolean; now: number;
|
||
}) {
|
||
return <><h3>Первый и последний рейс</h3>
|
||
{available ? <div className="service-window">
|
||
{[
|
||
{ label: 'Последний сегодня', departure: lastToday, empty: 'Сегодня рейсов нет', ended: Boolean(lastToday && Date.parse(lastToday.scheduledAt) + 60000 <= now) },
|
||
{ label: 'Первый завтра', departure: firstTomorrow, empty: tomorrowAvailable ? 'Завтра рейсов нет' : 'Расписание на завтра недоступно', ended: false },
|
||
].map(item => <div className="service-boundary" key={item.label}>
|
||
<div className="service-label">{item.label}{item.ended && <span>время прошло</span>}</div>
|
||
{item.departure ? <><time dateTime={item.departure.scheduledAt}><NumericText value={item.departure.scheduledTime} /></time>
|
||
<div className="service-trip"><RouteBadge number={item.departure.routeNumber} filled /><span>{item.departure.destination}</span></div>
|
||
</> : <p className="service-empty">{item.empty}</p>}
|
||
</div>)}
|
||
</div> : <p className="service-unavailable">{loading ? 'Загружаем полное расписание' : 'Полное расписание пока недоступно'}</p>}
|
||
</>;
|
||
}
|