From e836e7dd4ed5e9fa60e949d159100040b22a8f48 Mon Sep 17 00:00:00 2001
From: Arne Rief <riearn@proton.me>
Date: Mon, 22 Dec 2025 21:20:39 +0100
Subject: Movement simulator for all and single robot, project v1 ready

---
 frontend/src/pages/Dashboard.tsx | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

(limited to 'frontend/src/pages/Dashboard.tsx')

diff --git a/frontend/src/pages/Dashboard.tsx b/frontend/src/pages/Dashboard.tsx
index 088fee2..b1b38e4 100644
--- a/frontend/src/pages/Dashboard.tsx
+++ b/frontend/src/pages/Dashboard.tsx
@@ -14,6 +14,8 @@ import type { Robot, RobotsResponse } from "../types/robot";
 function Dashboard() {
     const [errorMessage, setErrorMessage] = useState<string>("");
     const [isLoading, setIsLoading] = useState<boolean>(true);
+    const [isSimulationActive, setIsSimulationActive] =
+        useState<boolean>(false);
     const [robots, setRobots] = useState<Robot[]>([]);
 
     const navigate = useNavigate();
@@ -25,6 +27,7 @@ function Dashboard() {
     async function handleLogout() {
         localStorage.removeItem("token-robot-tracker");
         localStorage.removeItem("user");
+        // setIsSimulationActive(false);
         navigate("/login", { replace: true });
     }
 
@@ -57,7 +60,9 @@ function Dashboard() {
                 }
 
                 const data: RobotsResponse = await response.json();
-                setRobots(data.data);
+                
+                setRobots(data.robots);
+                setIsSimulationActive(data.simulationRunning);
             } catch (error) {
                 console.error("Failed to load the robots:", error);
 
@@ -66,7 +71,6 @@ function Dashboard() {
                 } else {
                     setErrorMessage("An unexpected error occurred.");
                 }
-
             } finally {
                 setIsLoading(false);
             }
@@ -78,7 +82,7 @@ function Dashboard() {
         const socket = io(API_URL);
 
         // Listen for real-time robot updates
-        socket.on("robots_update", (updatedRobots) => {
+        socket.on("robots_update", ({ updatedRobots }) => {
             setRobots(updatedRobots);
         });
 
@@ -95,10 +99,13 @@ function Dashboard() {
             <Header user={user} logout={handleLogout} />
             <CityMap robots={robots} />
             <Sidebar
+                activeSimulation={isSimulationActive}
                 errorMessage={errorMessage}
                 robots={robots}
                 token={token}
+                setActiveSimulation={setIsSimulationActive}
                 setErrorMessage={setErrorMessage}
+                setRobots={setRobots}
             />
         </div>
     );
-- 
cgit v1.2.3

