From 323bc464fb79779e703c2dc7bbef567a3d4271de Mon Sep 17 00:00:00 2001 From: Caleb Denio Date: Sun, 22 Nov 2026 19:42:37 -0700 Subject: [PATCH] loading screen --- README.md | 4 ++++ TODO.md | 4 ++-- cmd/main.go | 28 ++++++++++++------------ static/index.html | 56 +++++++++++++++++++++++++++++++++++++++++++++-- static/js/main.js | 11 ++++++++-- 5 files changed, 83 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index d851184..415ad3c 100644 --- a/README.md +++ b/README.md @@ -7,5 +7,9 @@ Tracking all the trains & buses in Salt Lake City. - `GET https://uta.clb.li/api.json`: List all vehicles currently in service (JSON) - `GET https://uta.clb.li/api`: Same as above, but Protobuf (see ![proto/schema.proto](./proto/schema.proto)) - `GET https://uta.clb.li/api/shapes/{shape_id}`: Get the geographic route "shape" for a given vehicle's `shape_id` +- `GET https://uta.clb.li/api/upcoming-departures?stationIds=...`: Show upcoming scheduled departures for a given station (or stations) + - `?stationIds=` comma-separated list of GTFS stop IDs + - `?from=` UNIX timestamp, show upcoming departures as of this time (defaults to current time) + - `?to=` number of seconds in the future to show departures (defaults to 3600, 1 hour) ![screenshot](screenshot.png) diff --git a/TODO.md b/TODO.md index bbe9527..546b275 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,3 @@ -- mobile - advanced filtering -- show stops for trip \ No newline at end of file +- show stops for trip +- `/upcoming-departures` should NOT show arrivals, only departures diff --git a/cmd/main.go b/cmd/main.go index a794800..9fac3af 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -358,20 +358,20 @@ type DbDeparture struct { // format: "NORTH (passing)", "SOUTH (passing)", "NORTH", "SOUTH" // "1" is the western track, "2" is the eastern track, "0" is unknown track var predictionData map[string][4]int = map[string][4]int{ - "21760": {1, 2, 1, 1}, // Roy Station - "21757": {0, 0, 1, 1}, // Clearfield Station - "21772": {1, 2, 0, 0}, // Layton Station - "21758": {0, 0, 1, 1}, // Farmington Station - "21759": {0, 0, 1, 1}, // Woods Cross Station - "23113": {1, 2, 1, 2}, // North Temple Station - "21771": {1, 2, 1, 2}, // Salt Lake Central Station - "23080": {2, 1, 1, 1}, // Murray Central Station - "23082": {0, 0, 2, 2}, // South Jordan Station - "23081": {1, 2, 0, 0}, // Draper Station - "23074": {1, 2, 1, 1}, // Lehi Station - "23071": {0, 0, 2, 2}, // American Fork Station - "25330": {2, 1, 2, 2}, // Vineyard Station - "23076": {0, 0, 2, 2}, // Orem Central Station + "21760": {1, 2, 1, 1}, // Roy + "21757": {0, 0, 1, 1}, // Clearfield + "21772": {1, 2, 0, 0}, // Layton + "21758": {0, 0, 1, 1}, // Farmington + "21759": {0, 0, 1, 1}, // Woods Cross + "23113": {1, 2, 1, 2}, // North Temple + "21771": {1, 2, 1, 2}, // Salt Lake Central + "23080": {2, 1, 1, 1}, // Murray Central + "23082": {0, 0, 2, 2}, // South Jordan + "23081": {1, 2, 0, 0}, // Draper + "23074": {1, 2, 1, 1}, // Lehi + "23071": {0, 0, 2, 2}, // American Fork + "25330": {2, 1, 2, 2}, // Vineyard + "23076": {0, 0, 2, 2}, // Orem Central } func predictPlatform(d DbDeparture) int { diff --git a/static/index.html b/static/index.html index 42986c5..9c04729 100644 --- a/static/index.html +++ b/static/index.html @@ -117,6 +117,10 @@ display: none; } + #map { + position: relative; + } + #map, #sidebar { grid-row: 3 / 4; @@ -178,6 +182,42 @@ display: flex; } } + + #loader { + position: absolute; + inset: 0; + background-color: rgba(0, 0, 0, 0.6); + z-index: 1000; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + transition-property: visibility, opacity; + transition-duration: 500ms; + } + + #loader.loader--hidden { + visibility: hidden; + opacity: 0; + } + + @keyframes spin { + 0% { + transform: rotate(0deg); + } + 100% { + transform: rotate(360deg); + } + } + + .spin { + animation: spin 2s linear infinite; + } + + #loader p { + color: white; + font-size: 20px; + } @@ -198,7 +238,19 @@ 🚲 -
+
+
+
+ + + + +
+

loading...

+
+
- + diff --git a/static/js/main.js b/static/js/main.js index d6e8c0f..2958cce 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -288,6 +288,8 @@ function renderVehicle(vehicle) { }); } +let isLoaded = false + async function reload() { const { vehicles = [], info } = await fetch("/api", { headers: { Accept: "application/json" } }).then((r) => r.json()); @@ -344,12 +346,17 @@ async function reload() { currentVehicles.delete(key) } } + + if (!isLoaded) { + document.getElementById("loader").classList.add("loader--hidden") + isLoaded = true + } + + setTimeout(() => reload(), 5000); } reload(); -setInterval(reload, 5000); - Alpine.data('app', () => ({ busLayer: true, brtLayer: true,