From 79f3c42b0c04c7fd77481c14e6e9c345677b8c42 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero <94913521+arielcostas@users.noreply.github.com> Date: Tue, 4 Mar 2025 00:51:42 +0100 Subject: Add table layout like iTranvias, remake settings page --- src/components/GroupedTable.tsx | 84 +++++++++++++++++++++++++++++++++++++++++ src/components/RegularTable.tsx | 70 ++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 src/components/GroupedTable.tsx create mode 100644 src/components/RegularTable.tsx (limited to 'src/components') diff --git a/src/components/GroupedTable.tsx b/src/components/GroupedTable.tsx new file mode 100644 index 0000000..6581967 --- /dev/null +++ b/src/components/GroupedTable.tsx @@ -0,0 +1,84 @@ +import { StopDetails } from "../pages/Estimates"; +import LineIcon from "./LineIcon"; + +interface GroupedTable { + data: StopDetails; + dataDate: Date | null; +} + +export const GroupedTable: React.FC = ({ data, dataDate }) => { + + const absoluteArrivalTime = (minutes: number) => { + const now = new Date() + const arrival = new Date(now.getTime() + minutes * 60000) + return Intl.DateTimeFormat(navigator.language, { + hour: '2-digit', + minute: '2-digit' + }).format(arrival) + } + + const formatDistance = (meters: number) => { + if (meters > 1024) { + return `${(meters / 1000).toFixed(1)} km`; + } else { + return `${meters} m`; + } + } + + const groupedEstimates = data.estimates.reduce((acc, estimate) => { + if (!acc[estimate.line]) { + acc[estimate.line] = []; + } + acc[estimate.line].push(estimate); + return acc; + }, {} as Record); + + const sortedLines = Object.keys(groupedEstimates).sort((a, b) => { + const firstArrivalA = groupedEstimates[a][0].minutes; + const firstArrivalB = groupedEstimates[b][0].minutes; + return firstArrivalA - firstArrivalB; + }); + + return + + + + + + + + + + + + + {sortedLines.map((line) => ( + groupedEstimates[line].map((estimate, idx) => ( + + {idx === 0 && ( + + )} + + + + + )) + ))} + + + {data?.estimates.length === 0 && ( + + + + + + )} +
Estimaciones de llegadas a las {dataDate?.toLocaleTimeString()}
LíneaRutaLlegadaDistancia
+ + {estimate.route}{`${estimate.minutes} min`} + {estimate.meters > -1 + ? formatDistance(estimate.meters) + : "No disponible" + } +
No hay estimaciones disponibles
+} \ No newline at end of file diff --git a/src/components/RegularTable.tsx b/src/components/RegularTable.tsx new file mode 100644 index 0000000..8f0605f --- /dev/null +++ b/src/components/RegularTable.tsx @@ -0,0 +1,70 @@ +import { StopDetails } from "../pages/Estimates"; +import LineIcon from "./LineIcon"; + +interface RegularTableProps { + data: StopDetails; + dataDate: Date | null; +} + +export const RegularTable: React.FC = ({ data, dataDate }) => { + + const absoluteArrivalTime = (minutes: number) => { + const now = new Date() + const arrival = new Date(now.getTime() + minutes * 60000) + return Intl.DateTimeFormat(navigator.language, { + hour: '2-digit', + minute: '2-digit' + }).format(arrival) + } + + const formatDistance = (meters: number) => { + if (meters > 1024) { + return `${(meters / 1000).toFixed(1)} km`; + } else { + return `${meters} m`; + } + } + + return + + + + + + + + + + + + + {data.estimates + .sort((a, b) => a.minutes - b.minutes) + .map((estimate, idx) => ( + + + + + + + ))} + + + {data?.estimates.length === 0 && ( + + + + + + )} +
Estimaciones de llegadas a las {dataDate?.toLocaleTimeString()}
LíneaRutaLlegadaDistancia
{estimate.route} + {estimate.minutes > 15 + ? absoluteArrivalTime(estimate.minutes) + : `${estimate.minutes} min`} + + {estimate.meters > -1 + ? formatDistance(estimate.meters) + : "No disponible" + } +
No hay estimaciones disponibles
+} \ No newline at end of file -- cgit v1.3