From be2391954dd7653f1eecb4f650228d41038ff27b Mon Sep 17 00:00:00 2001
From: Ariel Costas Guerrero <ariel@costas.dev>
Date: Sat, 22 Nov 2025 18:07:33 +0100
Subject: feat: Update StopMapModal and Estimates to use selectedCirculationId
 for better clarity and consistency

---
 src/frontend/app/routes/stops-$id.tsx | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

(limited to 'src/frontend/app/routes/stops-$id.tsx')

diff --git a/src/frontend/app/routes/stops-$id.tsx b/src/frontend/app/routes/stops-$id.tsx
index 024ea73..7b11a95 100644
--- a/src/frontend/app/routes/stops-$id.tsx
+++ b/src/frontend/app/routes/stops-$id.tsx
@@ -37,6 +37,13 @@ export interface ConsolidatedCirculation {
   };
 }
 
+export const getCirculationId = (c: ConsolidatedCirculation): string => {
+  if (c.schedule?.tripId) {
+    return `trip:${c.schedule.tripId}`;
+  }
+  return `rt:${c.line}:${c.route}:${c.realTime?.minutes ?? "?"}`;
+};
+
 interface ErrorInfo {
   type: "network" | "server" | "unknown";
   status?: number;
@@ -80,8 +87,8 @@ export default function Estimates() {
   const [favourited, setFavourited] = useState(false);
   const [isManualRefreshing, setIsManualRefreshing] = useState(false);
   const [isMapModalOpen, setIsMapModalOpen] = useState(false);
-  const [selectedCirculationIdx, setSelectedCirculationIdx] = useState<
-    number | undefined
+  const [selectedCirculationId, setSelectedCirculationId] = useState<
+    string | undefined
   >(undefined);
   const { region } = useApp();
   const regionConfig = getRegionConfig(region);
@@ -255,7 +262,7 @@ export default function Estimates() {
               dataDate={dataDate}
               regionConfig={regionConfig}
               onCirculationClick={(estimate, idx) => {
-                setSelectedCirculationIdx(idx);
+                setSelectedCirculationId(getCirculationId(estimate));
                 setIsMapModalOpen(true);
               }}
             />
@@ -268,6 +275,7 @@ export default function Estimates() {
             stop={stopData}
             region={region}
             circulations={(data ?? []).map((c) => ({
+              id: getCirculationId(c),
               line: c.line,
               route: c.route,
               currentPosition: c.currentPosition,
@@ -279,7 +287,7 @@ export default function Estimates() {
             }))}
             isOpen={isMapModalOpen}
             onClose={() => setIsMapModalOpen(false)}
-            selectedCirculationIndex={selectedCirculationIdx}
+            selectedCirculationId={selectedCirculationId}
           />
         )}
       </div>
-- 
cgit v1.3

