diff --git a/apps/dashboard/src/App.tsx b/apps/dashboard/src/App.tsx index fb05fc6..6a51fbb 100644 --- a/apps/dashboard/src/App.tsx +++ b/apps/dashboard/src/App.tsx @@ -1,9 +1,9 @@ import { useQuery } from "@tanstack/react-query" import Chart from "chart.js/auto" -import { Fragment, useEffect, useLayoutEffect, useRef, useState } from "react" +import { useEffect, useLayoutEffect, useRef, useState } from "react" import { beszelSystemsQuery } from "./beszel" import cn from "./components/lib/cn" -import { StatusSeverity, formatLineName, tflDisruptionsQuery } from "./tfl" +import { StatusSeverity, TubeLine, formatLineName, tflDisruptionsQuery } from "./tfl" import { DEFAULT_LATITUDE, DEFAULT_LONGITUDE, @@ -15,31 +15,27 @@ import { function App() { return ( -
- - - - - +
+
+ + + + + + +
) } -function Tile({ - decorations = true, - children, - className, -}: { decorations?: boolean; children: React.ReactNode; className?: string }) { +function Tile({ children, className }: { children?: React.ReactNode; className?: string }) { return ( -
- {decorations && ( - <> -
-
-
-
- +
{children}
) @@ -69,8 +65,8 @@ function DateTimeTile() { return ( -

{formattedDate}

-

{formattedTime}

+

{formattedDate}

+

{formattedTime}

) } @@ -164,14 +160,14 @@ function WeatherTile() {
key={index} - className={cn("w-10 bg-teal-400 h-[2px]")} + className={cn("w-10 bg-teal-500 dark:bg-teal-400 h-[2px]")} />

{temperature}°

@@ -187,7 +183,7 @@ function WeatherTile() { className={cn( "w-4", index >= highlightIndexStart - ? "bg-teal-400 w-8 h-[2px]" + ? "bg-teal-500 dark:bg-teal-400 w-8 h-[2px]" : "bg-neutral-400 w-4 h-[1px]", )} /> @@ -209,7 +205,16 @@ function WeatherTile() { ) } -function TFLTile() { +function TFLTile({ className }: { className?: string }) { + const linesIDontCareAbout = [ + TubeLine.WaterlooCity, + TubeLine.Windrush, + TubeLine.Lioness, + TubeLine.Lioness, + TubeLine.Tram, + TubeLine.Mildmay, + ] + const { data: tflData, isLoading: isLoadingTFL, @@ -222,6 +227,7 @@ function TFLTile() { if (b.lineName.match(/northern/i)) return 1 return a.statusSeverity - b.statusSeverity }) + data.disruptions = data.disruptions.filter((disruption) => !linesIDontCareAbout.includes(disruption.lineId)) return data }, refetchInterval: 5 * 60 * 1000, // 5 minutes @@ -230,7 +236,9 @@ function TFLTile() { if (isLoadingTFL) { return ( - +

Loading tube status

) @@ -238,7 +246,9 @@ function TFLTile() { if (errorTFL) { return ( - +

Error loading from TfL

{errorTFL?.message}

@@ -247,7 +257,9 @@ function TFLTile() { if (!tflData) { return ( - +

No TfL data available

) @@ -255,33 +267,33 @@ function TFLTile() { return ( {tflData.goodService.includes("Northern") && ( - <> - -
- + )} - {tflData.disruptions.map((disruption, i) => ( - - - {i < tflData.disruptions.length - 1 &&
} -
+ {tflData.disruptions.map((disruption) => ( + ))}
) } -function TFLDistruptionItem({ lineId, reason, severity }: { lineId: string; reason: string; severity: number }) { +function TFLDistruptionItem({ lineId, reason, severity }: { lineId: TubeLine; reason: string; severity: number }) { const lineName = formatLineName(lineId) - console.log(lineId) let lineStyleClass: string switch (lineId) { case "bakerloo": @@ -377,13 +389,18 @@ function TFLDistruptionItem({ lineId, reason, severity }: { lineId: string; reas return ( <>
-

+

{lineName}

@@ -470,17 +487,14 @@ function SystemTile({ if (!beszelSystemsData) { return ( - +

No system status available

) } return ( - +

{displayName}

diff --git a/apps/dashboard/src/tfl.ts b/apps/dashboard/src/tfl.ts index 8b7bbef..26bad37 100644 --- a/apps/dashboard/src/tfl.ts +++ b/apps/dashboard/src/tfl.ts @@ -9,7 +9,7 @@ const API_BASE_URL = import.meta.env.VITE_API_URL || "http://localhost:8000" // Disruption Summary export interface DisruptionSummary { - lineId: string + lineId: TubeLine lineName: string mode: string status: string @@ -53,6 +53,27 @@ export enum StatusSeverity { ServiceClosed = 20, } +export enum TubeLine { + Bakerloo = "bakerloo", + Central = "central", + Circle = "circle", + District = "district", + HammersmithCity = "hammersmith-city", + Jubilee = "jubilee", + Metropolitan = "metropolitan", + Northern = "northern", + Piccadilly = "piccadilly", + Victoria = "victoria", + WaterlooCity = "waterloo-city", + LondonOverground = "london-overground", + DLR = "dlr", + Elizabeth = "elizabeth", + Tram = "tram", + Lioness = "lioness", + Windrush = "windrush", + Mildmay = "mildmay", +} + // Helper function to get severity color export function getSeverityColor(severity: number): string { if (severity >= 10) return "green" // Good Service @@ -90,25 +111,25 @@ export function getSeverityLabel(severity: number): string { } // Helper function to format line name for display -export function formatLineName(lineId: string): string { - const lineNames: Record = { - bakerloo: "Bakerloo", - central: "Central", - circle: "Circle", - district: "District", - "hammersmith-city": "H&C", - jubilee: "Jubilee", - metropolitan: "Metropolitan", - northern: "Northern", - piccadilly: "Piccadilly", - victoria: "Victoria", - "waterloo-city": "W&C", - "london-overground": "London Overground", - dlr: "DLR", - "elizabeth-line": "Elizabeth Line", - tram: "Tram", +export function formatLineName(line: TubeLine): string { + const lineNames: Record = { + [TubeLine.Bakerloo]: "Bakerloo", + [TubeLine.Central]: "Central", + [TubeLine.Circle]: "Circle", + [TubeLine.District]: "District", + [TubeLine.HammersmithCity]: "H&C", + [TubeLine.Jubilee]: "Jubilee", + [TubeLine.Metropolitan]: "Met", + [TubeLine.Northern]: "Northern", + [TubeLine.Piccadilly]: "Piccadilly", + [TubeLine.Victoria]: "Victoria", + [TubeLine.WaterlooCity]: "W&C", + [TubeLine.LondonOverground]: "London Overground", + [TubeLine.DLR]: "DLR", + [TubeLine.Elizabeth]: "Lizzie", + [TubeLine.Tram]: "Tram", } - return lineNames[lineId] || lineId + return lineNames[line] || line } /**