import { h } from 'preact'; import Box from './components/Box'; import Button from './components/Button'; import Heading from './components/Heading'; import Link from './components/Link'; import { useConfig, useStats } from './api'; import { Table, Tbody, Thead, Tr, Th, Td } from './components/Table'; import { useCallback, useEffect, useState } from 'preact/hooks'; export default function Debug() { const config = useConfig(); const [timeoutId, setTimeoutId] = useState(null); const forceUpdate = useCallback(async () => { setTimeoutId(setTimeout(forceUpdate, 1000)); }, []); useEffect(() => { forceUpdate(); }, []); useEffect(() => { return () => { clearTimeout(timeoutId); }; }, [timeoutId]); const { data: stats, status } = useStats(null, timeoutId); if (!stats) { return 'loading…'; } const { detectors, detection_fps, service, ...cameras } = stats; const detectorNames = Object.keys(detectors); const detectorDataKeys = Object.keys(detectors[detectorNames[0]]); const cameraNames = Object.keys(cameras); const cameraDataKeys = Object.keys(cameras[cameraNames[0]]); const handleCopyConfig = useCallback(async () => { await window.navigator.clipboard.writeText(JSON.stringify(config, null, 2)); }, [config]); return (
Debug {service.version} {detectorDataKeys.map((name) => ( ))} {detectorNames.map((detector, i) => ( {detectorDataKeys.map((name) => ( ))} ))}
detector{name.replace('_', ' ')}
{detector}{detectors[detector][name]}
{cameraDataKeys.map((name) => ( ))} {cameraNames.map((camera, i) => ( {cameraDataKeys.map((name) => ( ))} ))}
camera{name.replace('_', ' ')}
{camera} {cameras[camera][name]}
Config
          {JSON.stringify(config, null, 2)}
        
); }