From 854be328986a09460249a55dbac3af26530c7b29 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Sun, 8 Mar 2026 23:12:05 +0100 Subject: Enhance StopItem component to display next arrivals and improve layout; update StopList to show arrivals for the first three stops --- src/frontend/app/components/StopItem.tsx | 119 +++++++++++++++++++++++++------ 1 file changed, 97 insertions(+), 22 deletions(-) (limited to 'src/frontend/app/components') diff --git a/src/frontend/app/components/StopItem.tsx b/src/frontend/app/components/StopItem.tsx index 35ccf6d..362798e 100644 --- a/src/frontend/app/components/StopItem.tsx +++ b/src/frontend/app/components/StopItem.tsx @@ -1,37 +1,112 @@ -import React from "react"; +import { Clock } from "lucide-react"; +import React, { useEffect, useState } from "react"; +import { useTranslation } from "react-i18next"; import { Link } from "react-router"; +import { fetchArrivals } from "../api/arrivals"; +import { type Arrival } from "../api/schema"; import StopDataProvider, { type Stop } from "../data/StopDataProvider"; import RouteIcon from "./RouteIcon"; interface StopItemProps { stop: Stop; + showArrivals?: boolean; } -const StopItem: React.FC = ({ stop }) => { +const StopItem: React.FC = ({ stop, showArrivals }) => { + const { t } = useTranslation(); + const [arrivals, setArrivals] = useState(null); + + useEffect(() => { + let mounted = true; + if (showArrivals) { + fetchArrivals(stop.stopId, true) + .then((res) => { + if (mounted) { + setArrivals(res.arrivals.slice(0, 3)); + } + }) + .catch(console.error); + } + return () => { + mounted = false; + }; + }, [showArrivals, stop.stopId]); + return ( -
  • +
  • -
    - - {stop.favourite && } - {StopDataProvider.getDisplayName(stop)} - - - ({stop.stopCode || stop.stopId}) - -
    -
    - {stop.lines?.map((lineObj) => ( - - ))} +
    +
    + + {stop.favourite && ( + + )} + {StopDataProvider.getDisplayName(stop)} + +
    + +
    + + {stop.stopId.split(":")[0]} + + + {stop.stopCode || stop.stopId.split(":")[1] || stop.stopId} + +
    + + {stop.lines && stop.lines.length > 0 && ( +
    + {stop.lines.map((lineObj) => ( + + ))} +
    + )} + + {showArrivals && arrivals && arrivals.length > 0 && ( +
    +
    + + + {t("estimates.next_arrivals", "Próximas llegadas")} + +
    + {arrivals.map((arr, i) => ( +
    +
    + +
    + + {arr.headsign.destination} + + + {arr.estimate.minutes}' + +
    + ))} +
    + )}
  • -- cgit v1.3