summaryrefslogtreecommitdiff
path: root/frontend/src/pages
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/pages')
-rw-r--r--frontend/src/pages/Dashboard.tsx13
1 files changed, 10 insertions, 3 deletions
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>
);