()
| 8 | import { cn } from "@/lib/utils"; |
| 9 | |
| 10 | export function DebugMenu() { |
| 11 | const [isOpen, setIsOpen] = useState(false); |
| 12 | const [debugInfo, setDebugInfo] = useState<any>(null); |
| 13 | const [loading, setLoading] = useState(false); |
| 14 | |
| 15 | useEffect(() => { |
| 16 | const handleKeyDown = (e: KeyboardEvent) => { |
| 17 | if (e.key === "F2") { |
| 18 | setIsOpen((prev) => !prev); |
| 19 | } |
| 20 | }; |
| 21 | |
| 22 | window.addEventListener("keydown", handleKeyDown); |
| 23 | return () => window.removeEventListener("keydown", handleKeyDown); |
| 24 | }, []); |
| 25 | |
| 26 | useEffect(() => { |
| 27 | if (isOpen) { |
| 28 | fetchDebugInfo(); |
| 29 | } |
| 30 | }, [isOpen]); |
| 31 | |
| 32 | const fetchDebugInfo = async () => { |
| 33 | setLoading(true); |
| 34 | try { |
| 35 | const info = await getDebugInfo(); |
| 36 | setDebugInfo({ |
| 37 | ...info, |
| 38 | userAgent: navigator.userAgent, |
| 39 | timestamp: new Date().toISOString(), |
| 40 | windowSize: `${window.innerWidth}x${window.innerHeight}`, |
| 41 | }); |
| 42 | } catch (err) { |
| 43 | console.error("Failed to fetch debug info", err); |
| 44 | setDebugInfo({ error: "Failed to fetch debug info from backend" }); |
| 45 | } finally { |
| 46 | setLoading(false); |
| 47 | } |
| 48 | }; |
| 49 | |
| 50 | const copyToClipboard = () => { |
| 51 | if (debugInfo) { |
| 52 | navigator.clipboard.writeText(JSON.stringify(debugInfo, null, 2)); |
| 53 | } |
| 54 | }; |
| 55 | |
| 56 | if (!isOpen) return null; |
| 57 | |
| 58 | return ( |
| 59 | <div className="fixed inset-0 z-[100] flex items-center justify-center bg-black/50 backdrop-blur-sm"> |
| 60 | <Card className="w-full max-w-2xl max-h-[80vh] overflow-hidden flex flex-col shadow-2xl border-primary/20"> |
| 61 | <CardHeader className="flex flex-row items-center justify-between border-b px-6 py-4 bg-muted/50"> |
| 62 | <CardTitle className="text-lg font-bold flex items-center gap-2"> |
| 63 | <div className="w-2 h-2 rounded-full bg-yellow-500 animate-pulse" /> |
| 64 | Debug Menu |
| 65 | </CardTitle> |
| 66 | <Button variant="ghost" size="icon" onClick={() => setIsOpen(false)}> |
| 67 | <X className="h-4 w-4" /> |
nothing calls this directly
no test coverage detected