import { h, Fragment } from 'preact'; import { useCallback, useState } from 'preact/hooks'; import { route } from 'preact-router'; import ActivityIndicator from '../components/ActivityIndicator'; import Button from '../components/Button'; import Delete from '../icons/Delete' import Dialog from '../components/Dialog'; import Heading from '../components/Heading'; import Link from '../components/Link'; import { FetchStatus, useApiHost, useEvent } from '../api'; import { Table, Thead, Tbody, Th, Tr, Td } from '../components/Table'; export default function Event({ eventId }) { const apiHost = useApiHost(); const { data, status } = useEvent(eventId); const [showDialog, setShowDialog] = useState(false); const [deleteStatus, setDeleteStatus] = useState(FetchStatus.NONE); const handleClickDelete = () => { setShowDialog(true); }; const handleDismissDeleteDialog = () => { setShowDialog(false); }; const handleClickDeleteDialog = useCallback(async () => { let success; try { const response = await fetch(`${apiHost}/api/events/${eventId}`, { method: 'DELETE' }); success = await (response.status < 300 ? response.json() : { success: true }); setDeleteStatus(success ? FetchStatus.LOADED : FetchStatus.ERROR); } catch (e) { setDeleteStatus(FetchStatus.ERROR); } if (success) { setDeleteStatus(FetchStatus.LOADED); setShowDialog(false); route('/events', true); } }, [apiHost, eventId, setShowDialog]); if (status !== FetchStatus.LOADED) { return } const startime = new Date(data.start_time * 1000); const endtime = new Date(data.end_time * 1000); return (
{data.camera} {data.label} {startime.toLocaleString()} {showDialog ? ( ) : null}
Key Value
Camera {data.camera}
Timeframe {startime.toLocaleString()} – {endtime.toLocaleString()}
Score {(data.top_score * 100).toFixed(2)}%
Zones {data.zones.join(', ')}
{data.has_clip ? ( Clip ) : (

No clip available

)} {data.has_snapshot ? 'Best image' : 'Thumbnail'} {`${data.label}
); }