2026-03-15 00:20:54 +00:00
|
|
|
/** @jsxImportSource @nym.sh/jrx */
|
|
|
|
|
import type { FeedItemRenderer } from "@aelis/core"
|
|
|
|
|
|
|
|
|
|
import { FeedCard, SansSerifText } from "@aelis/components"
|
|
|
|
|
|
2026-03-30 00:00:41 +01:00
|
|
|
import type { TflAlertData, TflStatusData } from "./types.ts"
|
2026-03-15 00:20:54 +00:00
|
|
|
|
|
|
|
|
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`
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 00:00:41 +01:00
|
|
|
function renderAlertRow(alert: TflAlertData) {
|
|
|
|
|
const severityLabel = SEVERITY_LABEL[alert.severity]
|
2026-03-15 00:20:54 +00:00
|
|
|
|
|
|
|
|
return (
|
2026-03-30 00:00:41 +01:00
|
|
|
<>
|
|
|
|
|
<SansSerifText
|
|
|
|
|
content={`${alert.lineName} · ${severityLabel}`}
|
|
|
|
|
style="text-base font-semibold"
|
|
|
|
|
/>
|
|
|
|
|
<SansSerifText content={alert.description} style="text-sm" />
|
|
|
|
|
{alert.closestStationDistance !== null ? (
|
2026-03-15 00:20:54 +00:00
|
|
|
<SansSerifText
|
2026-03-30 00:00:41 +01:00
|
|
|
content={`Nearest station: ${formatDistance(alert.closestStationDistance)}`}
|
2026-03-15 00:20:54 +00:00
|
|
|
style="text-xs text-stone-500"
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
2026-03-30 00:00:41 +01:00
|
|
|
</>
|
2026-03-15 00:20:54 +00:00
|
|
|
)
|
|
|
|
|
}
|
2026-03-30 00:00:41 +01:00
|
|
|
|
|
|
|
|
export const renderTflStatus: FeedItemRenderer<"tfl-status", TflStatusData> = (item) => {
|
|
|
|
|
return <FeedCard>{item.data.alerts.map((alert) => renderAlertRow(alert))}</FeedCard>
|
|
|
|
|
}
|