From dc20c2ba8377a90a3170642c9b3df6cd5166ad72 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero <94913521+arielcostas@users.noreply.github.com> Date: Sun, 25 Aug 2024 23:12:48 +0200 Subject: Initial commit --- src/pages/Stop.tsx | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/pages/Stop.tsx (limited to 'src/pages/Stop.tsx') diff --git a/src/pages/Stop.tsx b/src/pages/Stop.tsx new file mode 100644 index 0000000..2ee077c --- /dev/null +++ b/src/pages/Stop.tsx @@ -0,0 +1,69 @@ +import { useParams } from "react-router-dom"; +import useSWR from "swr"; + +interface StopDetails { + stop: { + id: number; + name: string; + latitude: number; + longitude: number; + } + estimates: [{ + line: string; + route: string; + minutes: number; + meters: number; + }] +} + +export function Stop(): JSX.Element { + const params = useParams(); + + const { data, error, isLoading } = useSWR('home', async () => { + let response; + + try { + response = await fetch(`/api/GetStopEstimates?id=${params.stopId}`) + return response.json() + } catch (error) { + console.error(error) + throw new Error(`Failed to fetch data, status ${response!.status}, body: ${await response!.text()}`) + } + }); + + if (isLoading) return

Loading...

+ if (error) return

Error: {JSON.stringify(error)}

+ if (data === undefined) return

No data

+ + return ( + <> +

{data?.stop.name} ({data?.stop.id})

+ + + + + + + + + + + + + + + {data.estimates + .sort((a, b) => a.minutes - b.minutes) + .map((estimate, idx) => ( + + + + + + + ))} + +
Estimaciones de llegadas
LĂ­neaRutaMinutosMetros
{estimate.line}{estimate.route}{estimate.minutes}{estimate.meters}
+ + ) +} -- cgit v1.3