import { useEffect, useRef, useState } from "react"; import { checkHealth } from "../services/api"; const POLL_INTERVAL_MS = 10000; export default function StatusBadge() { const [health, setHealth] = useState(null); const [phase, setPhase] = useState("checking"); // 'checking' | 'online' | 'offline' const mountedRef = useRef(true); useEffect(() => { mountedRef.current = true; let cancelled = false; const poll = async () => { const result = await checkHealth(); if (cancelled || !mountedRef.current) return; if (result?.model_loaded) { setHealth(result); setPhase("online"); } else { setHealth(result); setPhase("offline"); } }; poll(); const interval = setInterval(poll, POLL_INTERVAL_MS); const onFocus = () => poll(); window.addEventListener("focus", onFocus); return () => { cancelled = true; mountedRef.current = false; clearInterval(interval); window.removeEventListener("focus", onFocus); }; }, []); if (phase === "checking") { return (