mirror of
https://github.com/kennethnym/aris.git
synced 2026-04-12 21:01:19 +01:00
TflSource.fetchItems() now returns one TflStatusFeedItem with an alerts array instead of separate items per line disruption. Signals use the highest severity. Alerts sorted by station distance. Co-authored-by: Ona <no-reply@ona.com>
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
/** @jsxImportSource @nym.sh/jrx */
|
|
import type { FeedItemRenderer } from "@aelis/core"
|
|
|
|
import { FeedCard, SansSerifText } from "@aelis/components"
|
|
|
|
import type { TflAlertData, TflStatusData } from "./types.ts"
|
|
|
|
import { TflAlertSeverity } from "./types.ts"
|
|
|
|
const SEVERITY_LABEL: Record<TflAlertSeverity, string> = {
|
|
[TflAlertSeverity.Closure]: "Closed",
|
|
[TflAlertSeverity.MajorDelays]: "Major delays",
|
|
[TflAlertSeverity.MinorDelays]: "Minor delays",
|
|
}
|
|
|
|
function formatDistance(km: number): string {
|
|
const meters = Math.round(km * 1000)
|
|
if (meters < 1000) {
|
|
return `${meters}m away`
|
|
}
|
|
return `${(meters / 1000).toFixed(1)}km away`
|
|
}
|
|
|
|
function renderAlertRow(alert: TflAlertData) {
|
|
const severityLabel = SEVERITY_LABEL[alert.severity]
|
|
|
|
return (
|
|
<>
|
|
<SansSerifText
|
|
content={`${alert.lineName} · ${severityLabel}`}
|
|
style="text-base font-semibold"
|
|
/>
|
|
<SansSerifText content={alert.description} style="text-sm" />
|
|
{alert.closestStationDistance !== null ? (
|
|
<SansSerifText
|
|
content={`Nearest station: ${formatDistance(alert.closestStationDistance)}`}
|
|
style="text-xs text-stone-500"
|
|
/>
|
|
) : null}
|
|
</>
|
|
)
|
|
}
|
|
|
|
export const renderTflStatus: FeedItemRenderer<"tfl-status", TflStatusData> = (item) => {
|
|
return <FeedCard>{item.data.alerts.map((alert) => renderAlertRow(alert))}</FeedCard>
|
|
}
|