Spaces:
Running

mcp-webcam / src /components /events /EventRow.tsx
evalstate's picture
evalstate HF Staff
Deploy mcp-webcam v0.3.0 (stateless MCP 2026-07-28 + SEP-3415 Events + Studio UI)
6f5f15e verified
Raw History Blame Contribute Delete
6.12 kB
import { useState } from 'react';
import { ChevronDown, ChevronRight, Copy, Image as ImageIcon, Radio, RefreshCw } from 'lucide-react';
import { toast } from 'sonner';
import type { EventLogEntry } from '../../../shared/api-types';
import { Badge } from '@/components/ui/badge';
import { formatBytes, formatClock, prettyCursor, shortId } from '@/lib/format';
export function EventRow({
entry,
onPreviewImage,
}: {
entry: EventLogEntry;
onPreviewImage: (title: string, subtitle: string, url: string) => void;
}) {
const [expanded, setExpanded] = useState(false);
const copy = async (label: string, value: string) => {
try {
await navigator.clipboard.writeText(value);
toast.success(`Copied ${label}`);
} catch {
toast.error('Clipboard copy failed');
}
};
const wirePayload = {
eventId: entry.eventId,
timestamp: entry.timestamp,
source: entry.source,
...(entry.message ? { message: entry.message } : {}),
...(entry.snapshot
? {
snapshot: {
eventId: entry.snapshot.eventId,
mimeType: entry.snapshot.mimeType,
width: entry.snapshot.width,
height: entry.snapshot.height,
bytes: entry.snapshot.bytes,
frozen: entry.snapshot.frozen,
resourceUri: `webcam://events/${entry.snapshot.eventId}/snapshot`,
tool: 'get_event_snapshot',
},
}
: {}),
};
return (
<div className="rounded-lg border border-line bg-panel-2/40 transition-colors hover:border-line-strong">
<div className="flex items-start gap-2.5 p-2.5">
<button
type="button"
onClick={() => setExpanded((e) => !e)}
className="mt-0.5 text-muted hover:text-fg cursor-pointer"
aria-label={expanded ? 'Collapse event details' : 'Expand event details'}
>
{expanded ? <ChevronDown className="h-3.5 w-3.5" /> : <ChevronRight className="h-3.5 w-3.5" />}
</button>
<div className="min-w-0 flex-1 space-y-1">
<div className="flex flex-wrap items-center gap-1.5">
<span className="font-mono text-[10.5px] tabular-nums text-muted">
{formatClock(entry.timestamp)}
</span>
<Badge variant="event" className="font-mono text-[10px]">
{entry.name}
</Badge>
{entry.source === 'auto' && (
<Badge variant="muted" className="text-[10px]">
auto
</Badge>
)}
<button
type="button"
onClick={() => void copy('eventId', entry.eventId)}
className="inline-flex items-center gap-1 font-mono text-[10.5px] text-muted hover:text-fg cursor-pointer"
title={`Copy ${entry.eventId}`}
>
<span>{shortId(entry.eventId, 16)}</span>
<Copy className="h-2.5 w-2.5 opacity-60" />
</button>
</div>
{entry.message && (
<p className="line-clamp-2 text-xs leading-snug text-fg">{entry.message}</p>
)}
<div className="flex flex-wrap items-center gap-2.5 text-[10.5px] text-muted tabular-nums">
<span className="inline-flex items-center gap-1 text-push">
<Radio className="h-3 w-3" />
push {entry.delivery.push}
</span>
<span className="inline-flex items-center gap-1 text-poll">
<RefreshCw className="h-3 w-3" />
poll {entry.delivery.poll}
</span>
<button
type="button"
onClick={() => void copy('cursor', entry.cursor)}
className="font-mono text-muted-2 hover:text-fg cursor-pointer"
title={`Copy cursor ${entry.cursor}`}
>
cur:{prettyCursor(entry.cursor)}
</button>
</div>
</div>
{entry.snapshot?.available && (
<button
type="button"
onClick={() =>
onPreviewImage(
`${entry.name} · ${entry.eventId}`,
`${entry.snapshot?.width ?? '?'}×${entry.snapshot?.height ?? '?'} · ${formatBytes(entry.snapshot?.bytes)}`,
entry.snapshot!.url,
)
}
className="group relative h-12 w-16 shrink-0 overflow-hidden rounded-md border border-line bg-zinc-950 cursor-pointer"
title="Click to preview snapshot"
>
<img
src={entry.snapshot.url}
alt={`Snapshot ${entry.eventId}`}
loading="lazy"
className="h-full w-full object-cover transition-transform group-hover:scale-105"
/>
<span className="absolute bottom-0.5 right-0.5 rounded bg-black/70 p-0.5 text-zinc-200 opacity-0 transition-opacity group-hover:opacity-100">
<ImageIcon className="h-2.5 w-2.5" />
</span>
</button>
)}
</div>
{expanded && (
<div className="space-y-2 border-t border-line bg-bg/60 px-3 py-2.5 text-[11px]">
<div className="flex flex-wrap items-center gap-1.5">
<span className="font-medium text-muted">Recipients:</span>
{entry.delivery.recipients.length > 0 ? (
entry.delivery.recipients.map((r) => (
<Badge key={r} variant="muted" className="font-mono text-[10px]">
{r}
</Badge>
))
) : (
<span className="text-muted-2">None yet (buffered in ring)</span>
)}
</div>
<div>
<div className="mb-1 text-[10px] font-semibold uppercase tracking-wider text-muted-2">
Wire Payload (image referenced, never inlined)
</div>
<pre className="overflow-x-auto rounded-md border border-line bg-panel p-2 font-mono text-[10.5px] leading-relaxed text-fg">
{JSON.stringify(wirePayload, null, 2)}
</pre>
</div>
</div>
)}
</div>
);
}