From 4b508e9309fb59ce1e36f4abc03bc4a4ec212ef7 Mon Sep 17 00:00:00 2001 From: Claas Date: Sun, 23 Jun 2024 14:18:54 +0200 Subject: [PATCH] Refactor to separate data from UI for easier management of files --- src/data.ts | 366 ++++++++++++++++++++++++++++++++++++++++ src/routes/journey.tsx | 372 +---------------------------------------- 2 files changed, 369 insertions(+), 369 deletions(-) create mode 100644 src/data.ts diff --git a/src/data.ts b/src/data.ts new file mode 100644 index 0000000..078e077 --- /dev/null +++ b/src/data.ts @@ -0,0 +1,366 @@ +type Line2 = { + type: "STR" | "Bus" | "RE" | "RB"; + color: string; + number: string; +}; +export type Changes = { + /** Optional because this could be the last connection and destination is set. */ + changes?: Connection[]; +}; +export type Transport = { + type: "transport"; + /** Start and at the same time destination of the parent connection before this if this is not the first connection */ + start: string; + line: Line2; + headsign: string; + /** Only set if this is the last connection/leaf in the connection tree. If this is the last connection, then changes should not exist */ + destination: string; + time: { + /** Time to change from the connection before this (parent connection). Optional because this could be the first connection */ + change?: string; + arrive: string; + depart: string; + duration: string; + delay?: { + arrive: string; + depart: string; + }; + }; + platform?: string; +}; + +export type Walk = { + type: "walk"; + timeAvailable: string; + distance: string; + time: string; + start: string; + destination: string; + + /** Optional because this could be the last connection and destination is set. */ + changes?: Connection[]; +}; +export type Connection = (Transport | Walk) & Changes; + +const WALK_BONN_HBF: Walk = { + type: "walk", + timeAvailable: "8min", + distance: "84m", + time: "6min", + start: "Hauptbahnhof, Bonn", + destination: "Bonn Hbf", +}; + +const WALK_BARBAROSSAPLATZ: Walk = { + type: "walk", + timeAvailable: "9min", + distance: "334m", + time: "8min", + start: "Köln Süd", + destination: "Barbarossaplatz, Köln", +}; + +const RE_WESEL_1628: Connection = { + type: "transport", + start: "Bonn Hbf", + line: { + type: "RE", + color: "bg-[#7C818B]", + number: "5 (28524)", + }, + headsign: "Wesel", + time: { + arrive: "16:21", + depart: "16:04", + duration: "17min", + delay: { + arrive: "16:45", + depart: "16:28", + }, + }, + platform: "1", + destination: "Köln Süd", + changes: [ + { + ...WALK_BARBAROSSAPLATZ, + timeAvailable: "9min", + changes: [ + { + type: "transport", + start: "Barbarossaplatz, Köln", + line: { + type: "STR", + color: "bg-[#9f3d53]", + number: "18", + }, + headsign: "Riehl Slabystr., Köln", + destination: "Neumarkt, Köln", + time: { + arrive: "16:57", + depart: "16:54", + duration: "3min", + delay: { + arrive: "16:57", + depart: "16:54", + }, + }, + }, + ], + }, + ], +}; + +const STR_NIEHL_1622: Connection = { + type: "transport", + start: "Hauptbahnhof, Bonn", + // line: "STR 16", + line: { + type: "STR", + color: "bg-[#9f3d53]", + number: "16", + }, + headsign: "Niehl Sebastianstr., Köln", + destination: "Neumarkt, Köln", + time: { + arrive: "17:15", + depart: "16:22", + duration: "53min", + delay: { + arrive: "16:22", + depart: "17:15", + }, + }, +}; + +const RB_MESSE_1633: Connection = { + type: "transport", + start: "Bonn Hbf", + line: { + type: "RB", + color: "bg-[#7C818B]", + number: "26 (25430)", + }, + headsign: "Köln Messe/Deutz", + destination: "Köln Süd", + time: { + arrive: "16:53", + depart: "16:33", + duration: "20min", + delay: { + arrive: "16:54", + depart: "16:34", + }, + }, + changes: [ + { + ...WALK_BARBAROSSAPLATZ, + timeAvailable: "8min", + changes: [ + { + type: "transport", + start: "Barbarossaplatz, Köln", + line: { + type: "STR", + color: "bg-[#9f3d53]", + number: "16", + }, + headsign: "Niehl Sebastianstr., Köln", + destination: "Neumarkt, Köln", + time: { + arrive: "17:05", + depart: "17:02", + duration: "3min", + delay: { + arrive: "17:05", + depart: "17:02", + }, + }, + }, + ], + }, + ], +}; + +function withChange( + connection: Transport, + change: string | undefined, +): Connection { + return { + ...connection, + time: { + ...connection.time, + change, + }, + }; +} + +export const connections: Connection[] = [ + { + type: "transport", + start: "Beuel Konrad-Adenauer-Platz, Bonn", + // line: "STR 62", + line: { + type: "STR", + color: "bg-[#9f3d53]", + number: "62", + }, + headsign: "Dottendorf Quirinusplatz, Bonn", + time: { + arrive: "16:07", + depart: "15:58", + duration: "9min", + }, + destination: "Hauptbahnhof, Bonn", + changes: [ + { + type: "transport", + start: "Hauptbahnhof, Bonn", + // line: "STR 16", + line: { + type: "STR", + color: "bg-[#9f3d53]", + number: "16", + }, + headsign: "Niehl Sebastianstr., Köln", + destination: "Neumarkt, Köln", + time: { + change: "5min", + arrive: "17:05", + depart: "16:12", + duration: "53min", + delay: { + arrive: "16:12", + depart: "17:05", + }, + }, + }, + withChange(STR_NIEHL_1622, "15min"), + { + ...WALK_BONN_HBF, + timeAvailable: "21min", + changes: [withChange(RE_WESEL_1628, undefined)], + }, + ], + }, + { + type: "transport", + start: "Beuel Konrad-Adenauer-Platz, Bonn", + // line: "STR 62", + line: { + type: "STR", + color: "bg-[#9f3d53]", + number: "62", + }, + headsign: "Dottendorf Quirinusplatz, Bonn", + destination: "Hauptbahnhof, Bonn", + time: { + arrive: "16:17", + depart: "16:08", + duration: "9min", + delay: { + arrive: "16:08", + depart: "16:17", + }, + }, + changes: [ + withChange(STR_NIEHL_1622, "5min"), + withChange(RE_WESEL_1628, "9min"), + ], + }, + { + type: "transport", + start: "Beuel Konrad-Adenauer-Platz, Bonn", + line: { + type: "Bus", + color: "bg-[#76408C]", + number: "117", + }, + headsign: "Hauptbahnhof, Bonn", + destination: "Hauptbahnhof, Bonn", + time: { + arrive: "16:15", + depart: "16:05", + duration: "10min", + }, + changes: [ + withChange(STR_NIEHL_1622, "4min"), + withChange(RE_WESEL_1628, "13min"), + ], + }, + + // Bus -> Walk -> RE + { + type: "transport", + start: "Beuel Konrad-Adenauer-Platz, Bonn", + line: { + type: "Bus", + color: "bg-[#76408C]", + number: "603", + }, + headsign: "Hauptbahnhof, Bonn", + destination: "Hauptbahnhof, Bonn", + time: { + arrive: "16:20", + depart: "16:09", + duration: "10min", + }, + changes: [ + { + ...WALK_BONN_HBF, + timeAvailable: "8min", + changes: [RE_WESEL_1628], + }, + ], + }, + { + type: "transport", + start: "Beuel Konrad-Adenauer-Platz, Bonn", + line: { + type: "STR", + color: "bg-[#9f3d53]", + number: "62", + }, + headsign: "Dottendorf Quirinusplatz, Bonn", + destination: "Hauptbahnhof, Bonn", + time: { + arrive: "16:27", + depart: "16:18", + duration: "9min", + }, + changes: [ + { + ...WALK_BONN_HBF, + timeAvailable: "7min", + changes: [RB_MESSE_1633], + }, + ], + }, + // 640 -> RB 26 + { + type: "transport", + start: "Beuel Konrad-Adenauer-Platz, Bonn", + line: { + type: "Bus", + color: "bg-[#76408C]", + number: "640", + }, + headsign: "Hauptbahnhof, Bonn", + destination: "Hauptbahnhof, Bonn", + time: { + arrive: "16:23", + depart: "16:13", + duration: "10min", + delay: { + arrive: "16:28", + depart: "16:18", + }, + }, + changes: [ + { + ...WALK_BONN_HBF, + timeAvailable: "6min", + changes: [RB_MESSE_1633], + }, + ], + }, +]; diff --git a/src/routes/journey.tsx b/src/routes/journey.tsx index 93e7984..07f1035 100644 --- a/src/routes/journey.tsx +++ b/src/routes/journey.tsx @@ -1,4 +1,5 @@ import { For, Match, Show, Switch, createSignal, type JSX } from "solid-js"; +import { Changes, Connection, Transport, Walk, connections } from "~/data"; function TransportConnection({ connection, @@ -144,7 +145,7 @@ function WalkConnection({ connection }: { connection: Walk }): JSX.Element { ); } -function Connection3(connection: Connection2): JSX.Element { +function Connection3(connection: Connection): JSX.Element { return (
{/* TODO make this aligned through grid to area below */} @@ -201,7 +202,7 @@ function Journey1() { data-row class="flex snap-x snap-mandatory grid-flow-col gap-4 overflow-x-auto overflow-y-scroll overscroll-x-contain *:flex-none" > - {Connection3} + {Connection3}
@@ -279,370 +280,3 @@ export default function Journeys() { ); } - -type Line2 = { - type: "STR" | "Bus" | "RE" | "RB"; - color: string; - number: string; -}; -type Changes = { - /** Optional because this could be the last connection and destination is set. */ - changes?: Connection2[]; -}; -type Transport = { - type: "transport"; - /** Start and at the same time destination of the parent connection before this if this is not the first connection */ - start: string; - line: Line2; - headsign: string; - /** Only set if this is the last connection/leaf in the connection tree. If this is the last connection, then changes should not exist */ - destination: string; - time: { - /** Time to change from the connection before this (parent connection). Optional because this could be the first connection */ - change?: string; - arrive: string; - depart: string; - duration: string; - delay?: { - arrive: string; - depart: string; - }; - }; - platform?: string; -}; - -type Walk = { - type: "walk"; - timeAvailable: string; - distance: string; - time: string; - start: string; - destination: string; - - /** Optional because this could be the last connection and destination is set. */ - changes?: Connection2[]; -}; -type Connection2 = (Transport | Walk) & Changes; - -const WALK_BONN_HBF: Walk = { - type: "walk", - timeAvailable: "8min", - distance: "84m", - time: "6min", - start: "Hauptbahnhof, Bonn", - destination: "Bonn Hbf", -}; - -const WALK_BARBAROSSAPLATZ: Walk = { - type: "walk", - timeAvailable: "9min", - distance: "334m", - time: "8min", - start: "Köln Süd", - destination: "Barbarossaplatz, Köln", -}; - -const RE_WESEL_1628: Connection2 = { - type: "transport", - start: "Bonn Hbf", - line: { - type: "RE", - color: "bg-[#7C818B]", - number: "5 (28524)", - }, - headsign: "Wesel", - time: { - arrive: "16:21", - depart: "16:04", - duration: "17min", - delay: { - arrive: "16:45", - depart: "16:28", - }, - }, - platform: "1", - destination: "Köln Süd", - changes: [ - { - ...WALK_BARBAROSSAPLATZ, - timeAvailable: "9min", - changes: [ - { - type: "transport", - start: "Barbarossaplatz, Köln", - line: { - type: "STR", - color: "bg-[#9f3d53]", - number: "18", - }, - headsign: "Riehl Slabystr., Köln", - destination: "Neumarkt, Köln", - time: { - arrive: "16:57", - depart: "16:54", - duration: "3min", - delay: { - arrive: "16:57", - depart: "16:54", - }, - }, - }, - ], - }, - ], -}; - -const STR_NIEHL_1622: Connection2 = { - type: "transport", - start: "Hauptbahnhof, Bonn", - // line: "STR 16", - line: { - type: "STR", - color: "bg-[#9f3d53]", - number: "16", - }, - headsign: "Niehl Sebastianstr., Köln", - destination: "Neumarkt, Köln", - time: { - arrive: "17:15", - depart: "16:22", - duration: "53min", - delay: { - arrive: "16:22", - depart: "17:15", - }, - }, -}; - -const RB_MESSE_1633: Connection2 = { - type: "transport", - start: "Bonn Hbf", - line: { - type: "RB", - color: "bg-[#7C818B]", - number: "26 (25430)", - }, - headsign: "Köln Messe/Deutz", - destination: "Köln Süd", - time: { - arrive: "16:53", - depart: "16:33", - duration: "20min", - delay: { - arrive: "16:54", - depart: "16:34", - }, - }, - changes: [ - { - ...WALK_BARBAROSSAPLATZ, - timeAvailable: "8min", - changes: [ - { - type: "transport", - start: "Barbarossaplatz, Köln", - line: { - type: "STR", - color: "bg-[#9f3d53]", - number: "16", - }, - headsign: "Niehl Sebastianstr., Köln", - destination: "Neumarkt, Köln", - time: { - arrive: "17:05", - depart: "17:02", - duration: "3min", - delay: { - arrive: "17:05", - depart: "17:02", - }, - }, - }, - ], - }, - ], -}; - -function withChange( - connection: Transport, - change: string | undefined, -): Connection2 { - return { - ...connection, - time: { - ...connection.time, - change, - }, - }; -} - -const connections2: Connection2[] = [ - { - type: "transport", - start: "Beuel Konrad-Adenauer-Platz, Bonn", - // line: "STR 62", - line: { - type: "STR", - color: "bg-[#9f3d53]", - number: "62", - }, - headsign: "Dottendorf Quirinusplatz, Bonn", - time: { - arrive: "16:07", - depart: "15:58", - duration: "9min", - }, - destination: "Hauptbahnhof, Bonn", - changes: [ - { - type: "transport", - start: "Hauptbahnhof, Bonn", - // line: "STR 16", - line: { - type: "STR", - color: "bg-[#9f3d53]", - number: "16", - }, - headsign: "Niehl Sebastianstr., Köln", - destination: "Neumarkt, Köln", - time: { - change: "5min", - arrive: "17:05", - depart: "16:12", - duration: "53min", - delay: { - arrive: "16:12", - depart: "17:05", - }, - }, - }, - withChange(STR_NIEHL_1622, "15min"), - { - ...WALK_BONN_HBF, - timeAvailable: "21min", - changes: [withChange(RE_WESEL_1628, undefined)], - }, - ], - }, - { - type: "transport", - start: "Beuel Konrad-Adenauer-Platz, Bonn", - // line: "STR 62", - line: { - type: "STR", - color: "bg-[#9f3d53]", - number: "62", - }, - headsign: "Dottendorf Quirinusplatz, Bonn", - destination: "Hauptbahnhof, Bonn", - time: { - arrive: "16:17", - depart: "16:08", - duration: "9min", - delay: { - arrive: "16:08", - depart: "16:17", - }, - }, - changes: [ - withChange(STR_NIEHL_1622, "5min"), - withChange(RE_WESEL_1628, "9min"), - ], - }, - { - type: "transport", - start: "Beuel Konrad-Adenauer-Platz, Bonn", - line: { - type: "Bus", - color: "bg-[#76408C]", - number: "117", - }, - headsign: "Hauptbahnhof, Bonn", - destination: "Hauptbahnhof, Bonn", - time: { - arrive: "16:15", - depart: "16:05", - duration: "10min", - }, - changes: [ - withChange(STR_NIEHL_1622, "4min"), - withChange(RE_WESEL_1628, "13min"), - ], - }, - - // Bus -> Walk -> RE - { - type: "transport", - start: "Beuel Konrad-Adenauer-Platz, Bonn", - line: { - type: "Bus", - color: "bg-[#76408C]", - number: "603", - }, - headsign: "Hauptbahnhof, Bonn", - destination: "Hauptbahnhof, Bonn", - time: { - arrive: "16:20", - depart: "16:09", - duration: "10min", - }, - changes: [ - { - ...WALK_BONN_HBF, - timeAvailable: "8min", - changes: [RE_WESEL_1628], - }, - ], - }, - { - type: "transport", - start: "Beuel Konrad-Adenauer-Platz, Bonn", - line: { - type: "STR", - color: "bg-[#9f3d53]", - number: "62", - }, - headsign: "Dottendorf Quirinusplatz, Bonn", - destination: "Hauptbahnhof, Bonn", - time: { - arrive: "16:27", - depart: "16:18", - duration: "9min", - }, - changes: [ - { - ...WALK_BONN_HBF, - timeAvailable: "7min", - changes: [RB_MESSE_1633], - }, - ], - }, - // 640 -> RB 26 - { - type: "transport", - start: "Beuel Konrad-Adenauer-Platz, Bonn", - line: { - type: "Bus", - color: "bg-[#76408C]", - number: "640", - }, - headsign: "Hauptbahnhof, Bonn", - destination: "Hauptbahnhof, Bonn", - time: { - arrive: "16:23", - depart: "16:13", - duration: "10min", - delay: { - arrive: "16:28", - depart: "16:18", - }, - }, - changes: [ - { - ...WALK_BONN_HBF, - timeAvailable: "6min", - changes: [RB_MESSE_1633], - }, - ], - }, -]; -- knotmirror 0.0.1