1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
import { RefreshCw } from "lucide-react";
import React from "react";
import { useTranslation } from "react-i18next";
import { Sheet } from "react-modal-sheet";
import { Link } from "react-router";
import { ArrivalList } from "~/components/arrivals/ArrivalList";
import { useStopArrivals } from "../../hooks/useArrivals";
import { ErrorDisplay } from "../ErrorDisplay";
import LineIcon from "../LineIcon";
import "./StopSummarySheet.css";
import { StopSummarySheetSkeleton } from "./StopSummarySheetSkeleton";
export interface StopSheetProps {
isOpen: boolean;
onClose: () => void;
stop: {
stopId: string;
stopCode?: string;
stopFeed?: string;
name: string;
};
}
export const StopSummarySheet: React.FC<StopSheetProps> = ({
isOpen,
onClose,
stop,
}) => {
const { t } = useTranslation();
const {
data,
isLoading: loading,
error,
refetch: loadData,
dataUpdatedAt,
} = useStopArrivals(stop.stopId, true, isOpen);
const lastUpdated = dataUpdatedAt ? new Date(dataUpdatedAt) : null;
// Show only the next 4 arrivals
const limitedEstimates = data?.arrivals.slice(0, 4) ?? [];
return (
<Sheet isOpen={isOpen} onClose={onClose} detent="content">
<Sheet.Container>
<Sheet.Header />
<Sheet.Content drag="y">
<div className="stop-sheet-content">
<div className="stop-sheet-header">
<h2 className="stop-sheet-title">{stop.name}</h2>
<span className="stop-sheet-id">({stop.stopCode})</span>
</div>
<div className={`flex flex-wrap flex-row gap-2`}>
{data?.routes.map((lineObj) => (
<LineIcon
key={lineObj.shortName}
line={lineObj.shortName}
mode="pill"
colour={lineObj.colour}
textColour={lineObj.textColour}
/>
))}
</div>
{/* TODO: Enable stop alerts when available */}
{/*<StopAlert stop={stop} compact />*/}
{loading ? (
<StopSummarySheetSkeleton />
) : error ? (
<ErrorDisplay
error={{
type: error.message.includes("HTTP") ? "server" : "network",
message: error.message,
}}
onRetry={() => loadData()}
title={t(
"errors.estimates_title",
"Error al cargar estimaciones"
)}
className="compact"
/>
) : data ? (
<>
<div className="stop-sheet-estimates">
<h3 className="stop-sheet-subtitle">
{t("estimates.next_arrivals", "Next arrivals")}
</h3>
{limitedEstimates.length === 0 ? (
<div className="stop-sheet-no-estimates">
{t("estimates.none", "No hay estimaciones disponibles")}
</div>
) : (
<ArrivalList arrivals={limitedEstimates} reduced />
)}
</div>
</>
) : null}
</div>
</Sheet.Content>
<div className="stop-sheet-footer">
{lastUpdated && (
<div className="stop-sheet-timestamp">
{t("estimates.last_updated", "Actualizado a las")}{" "}
{lastUpdated.toLocaleTimeString(undefined, {
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
})}
</div>
)}
<div className="stop-sheet-actions">
<button
className="stop-sheet-reload"
onClick={loadData}
disabled={loading}
title={t("estimates.reload", "Recargar estimaciones")}
>
<RefreshCw
className={`reload-icon ${loading ? "spinning" : ""}`}
/>
{t("estimates.reload", "Recargar")}
</button>
<Link
to={`/stops/${stop.stopId}`}
className="stop-sheet-view-all"
onClick={onClose}
>
{t("map.view_all_estimates", "Ver todas las estimaciones")}
</Link>
</div>
</div>
</Sheet.Container>
<Sheet.Backdrop onTap={onClose} />
</Sheet>
);
};
|