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, 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.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}'
    ))}
    )}
  • ); }; export default StopItem;