diff options
| author | Arne Rief <riearn@proton.me> | 2025-12-22 12:56:20 +0100 |
|---|---|---|
| committer | Arne Rief <riearn@proton.me> | 2025-12-22 13:02:01 +0100 |
| commit | d1b64ddd78d8b8dc3eca76038a75071ab2a575d9 (patch) | |
| tree | 6213650195cdddb0ec4938380735ebd70847a758 /frontend/src/pages/Dashboard.tsx | |
| parent | 3818739c5901cc3f1d4596b24cfe1b827a2eca23 (diff) | |
Sidebar split into smaller components
Diffstat (limited to 'frontend/src/pages/Dashboard.tsx')
| -rw-r--r-- | frontend/src/pages/Dashboard.tsx | 74 |
1 files changed, 2 insertions, 72 deletions
diff --git a/frontend/src/pages/Dashboard.tsx b/frontend/src/pages/Dashboard.tsx index b8dd2c4..088fee2 100644 --- a/frontend/src/pages/Dashboard.tsx +++ b/frontend/src/pages/Dashboard.tsx @@ -14,7 +14,6 @@ import type { Robot, RobotsResponse } from "../types/robot"; function Dashboard() { const [errorMessage, setErrorMessage] = useState<string>(""); const [isLoading, setIsLoading] = useState<boolean>(true); - const [isSimulationActive, setIsSimulationActive] = useState(false); const [robots, setRobots] = useState<Robot[]>([]); const navigate = useNavigate(); @@ -29,72 +28,6 @@ function Dashboard() { navigate("/login", { replace: true }); } - async function handleStartAllRobots() { - setIsSimulationActive(true); - - try { - const response = await fetch(`${API_URL}/robots/move`, { - method: "POST", - headers: { - Authorization: `Bearer ${token}`, - "Content-Type": "application/json", - }, - }); - - if (!response.ok) { - const errorData: ErrorResponse = await response.json(); - throw new Error( - errorData.message || "Failed to set all robots moving." - ); - } - - console.log("All robots set moving."); - } catch (error) { - console.error("Error starting robots:", error); - - if (error instanceof Error) { - setErrorMessage(error.message); - } else { - setErrorMessage("An unexpected error occurred."); - } - - setIsSimulationActive(false); - } - } - - async function handleStopAllRobots() { - setIsSimulationActive(false); - - try { - const response = await fetch(`${API_URL}/robots/stop`, { - method: "POST", - headers: { - Authorization: `Bearer ${token}`, - "Content-Type": "application/json", - }, - }); - - if (!response.ok) { - const errorData: ErrorResponse = await response.json(); - throw new Error( - errorData.message || "Failed to set all robots idle." - ); - } - - console.log("All robots set idle."); - } catch (error) { - console.error("Error stopping robots:", error); - - if (error instanceof Error) { - setErrorMessage(error.message); - } else { - setErrorMessage("An unexpected error occurred."); - } - - setIsSimulationActive(true); - } - } - // Request robot data from backend on component mount useEffect(() => { // Additional safety check to protect this page from unauthorized access @@ -162,13 +95,10 @@ function Dashboard() { <Header user={user} logout={handleLogout} /> <CityMap robots={robots} /> <Sidebar - activeSimulation={isSimulationActive} errorMessage={errorMessage} - setErrorMessage={setErrorMessage} - token={token} robots={robots} - onStartAllRobots={handleStartAllRobots} - onStopAllRobots={handleStopAllRobots} + token={token} + setErrorMessage={setErrorMessage} /> </div> ); |
