import { useState, useCallback } from "react"; import Dashboard from "./pages/Dashboard"; import RadarView3D from "./pages/RadarView3D"; import PatientForm from "./pages/PatientForm"; import AdminPanel from "./pages/AdminPanel"; import "./App.css"; const API = import.meta.env.PROD ? window.location.origin : "http://localhost:8000"; const TABS = [ { id: "dashboard", label: "Overview" }, { id: "map", label: "Live simulation" }, { id: "patient", label: "Dispatch" }, { id: "admin", label: "System" }, ]; export default function App() { const [activeTab, setActiveTab] = useState("dashboard"); const [simRunning, setSimRunning] = useState(false); // FIX 1: Optimistic UI Update for instant, smooth toggling const toggleSim = useCallback(async () => { const nextState = !simRunning; setSimRunning(nextState); // Update UI instantly try { await fetch(`${API}/simulation/${nextState ? "start" : "stop"}`); } catch (e) { console.warn("Backend unreached, reverting local sim state.", e); setSimRunning(!nextState); // Revert safely if it fails } }, [simRunning]); return (
{/* ── TOP MENU BAR ── */}
Smart Routing System
{simRunning ? "SYS.ACTIVE" : "SYS.IDLE"}
{/* ── MAIN WORKSPACE ── */}
{/* SIDEBAR NAVIGATION */}
{/* CONTENT AREA */}
PATH /{TABS.find(t => t.id === activeTab)?.label}
{/* The new 3D Interactive Map */}
); }