From ee69c62adc5943a1dbd154df5142c0e726bdd317 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Fri, 13 Mar 2026 16:49:10 +0100 Subject: feat(routes): add realtime estimates panel with pattern-aware styling - New GET /api/stops/estimates endpoint (nano mode: tripId, patternId, estimate, delay only) - useStopEstimates hook wiring estimates to routes-$id stop panel - Pattern-aware styling: dim schedules and estimates from other patterns - Past scheduled departures shown with strikethrough instead of hidden - Persist selected pattern in URL hash (replace navigation, no history push) - Fix planner arrivals using new estimates endpoint --- src/frontend/app/api/arrivals.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/frontend/app/api/arrivals.ts') diff --git a/src/frontend/app/api/arrivals.ts b/src/frontend/app/api/arrivals.ts index 8ae6e78..ad99630 100644 --- a/src/frontend/app/api/arrivals.ts +++ b/src/frontend/app/api/arrivals.ts @@ -1,6 +1,8 @@ import { StopArrivalsResponseSchema, + StopEstimatesResponseSchema, type StopArrivalsResponse, + type StopEstimatesResponse, } from "./schema"; export const fetchArrivals = async ( @@ -29,3 +31,31 @@ export const fetchArrivals = async ( throw e; } }; + +export const fetchEstimates = async ( + stopId: string, + routeId: string, + viaStopId?: string +): Promise => { + let url = `/api/stops/estimates?stop=${encodeURIComponent(stopId)}&route=${encodeURIComponent(routeId)}`; + if (viaStopId) { + url += `&via=${encodeURIComponent(viaStopId)}`; + } + + const resp = await fetch(url, { + headers: { Accept: "application/json" }, + }); + + if (!resp.ok) { + throw new Error(`HTTP ${resp.status}: ${resp.statusText}`); + } + + const data = await resp.json(); + try { + return StopEstimatesResponseSchema.parse(data); + } catch (e) { + console.error("Zod parsing failed for estimates:", e); + console.log("Received data:", data); + throw e; + } +}; -- cgit v1.3