Spaces:
Running
Running
Download src/components/activity/ActivityFeed.tsx from evalstate/mcp-webcam: direct link, hf CLI and curl.
- Browser
- Download file 5.29 kB
-
https://huggingface.co/spaces/evalstate/mcp-webcam/resolve/main/src/components/activity/ActivityFeed.tsx
- Command line
-
hf download hf://spaces/evalstate/mcp-webcam/src/components/activity/ActivityFeed.tsx
-
curl -L -o ActivityFeed.tsx https://huggingface.co/spaces/evalstate/mcp-webcam/resolve/main/src/components/activity/ActivityFeed.tsx
5.29 kB
| import { useState } from 'react'; | |
| import { | |
| Activity, | |
| AlertCircle, | |
| Camera, | |
| Radio, | |
| RefreshCw, | |
| SlidersHorizontal, | |
| Sparkles, | |
| Terminal, | |
| Trash2, | |
| } from 'lucide-react'; | |
| import { toast } from 'sonner'; | |
| import type { ActivityEntry, ActivityKind } from '../../../shared/api-types'; | |
| import { Badge } from '@/components/ui/badge'; | |
| import { Button } from '@/components/ui/button'; | |
| import { EmptyState } from '@/components/ui/empty-state'; | |
| import { formatClock } from '@/lib/format'; | |
| import { cn } from '@/lib/utils'; | |
| type FilterKind = 'all' | 'events' | 'subscriptions' | 'calls'; | |
| function matchesFilter(kind: ActivityKind, filter: FilterKind): boolean { | |
| if (filter === 'all') return true; | |
| if (filter === 'events') return kind === 'event.fired'; | |
| if (filter === 'subscriptions') { | |
| return ( | |
| kind === 'stream.opened' || | |
| kind === 'stream.closed' || | |
| kind === 'stream.dropped' || | |
| kind === 'stream.revoked' || | |
| kind === 'stream.error' || | |
| kind === 'poll' || | |
| kind === 'poll.error' | |
| ); | |
| } | |
| return kind === 'call' || kind === 'capture' || kind === 'capture.error'; | |
| } | |
| function KindIcon({ kind }: { kind: ActivityKind }) { | |
| if (kind === 'event.fired') return <Sparkles className="h-3.5 w-3.5 text-event shrink-0" />; | |
| if (kind.startsWith('stream.')) { | |
| return kind === 'stream.error' || kind === 'stream.revoked' ? ( | |
| <AlertCircle className="h-3.5 w-3.5 text-danger shrink-0" /> | |
| ) : ( | |
| <Radio className="h-3.5 w-3.5 text-push shrink-0" /> | |
| ); | |
| } | |
| if (kind === 'poll' || kind === 'poll.error') { | |
| return kind === 'poll.error' ? ( | |
| <AlertCircle className="h-3.5 w-3.5 text-danger shrink-0" /> | |
| ) : ( | |
| <RefreshCw className="h-3.5 w-3.5 text-poll shrink-0" /> | |
| ); | |
| } | |
| if (kind === 'call') return <Terminal className="h-3.5 w-3.5 text-call shrink-0" />; | |
| if (kind === 'capture' || kind === 'capture.error') { | |
| return ( | |
| <Camera | |
| className={cn('h-3.5 w-3.5 shrink-0', kind === 'capture.error' ? 'text-danger' : 'text-push')} | |
| /> | |
| ); | |
| } | |
| if (kind === 'config') return <SlidersHorizontal className="h-3.5 w-3.5 text-muted shrink-0" />; | |
| return <Activity className="h-3.5 w-3.5 text-muted shrink-0" />; | |
| } | |
| export function ActivityFeed({ | |
| entries, | |
| onClear, | |
| }: { | |
| entries: ActivityEntry[]; | |
| onClear: () => Promise<void>; | |
| }) { | |
| const [filter, setFilter] = useState<FilterKind>('all'); | |
| const filtered = entries.filter((e) => matchesFilter(e.kind, filter)); | |
| return ( | |
| <div className="space-y-2.5"> | |
| <div className="flex flex-wrap items-center justify-between gap-2"> | |
| <div className="inline-flex rounded-lg border border-line bg-panel-2/60 p-0.5 text-[11px]"> | |
| {( | |
| [ | |
| ['all', 'All'], | |
| ['events', 'Events'], | |
| ['subscriptions', 'Subscriptions'], | |
| ['calls', 'Calls'], | |
| ] as const | |
| ).map(([id, label]) => ( | |
| <button | |
| key={id} | |
| type="button" | |
| onClick={() => setFilter(id)} | |
| className={cn( | |
| 'rounded-md px-2 py-0.5 font-medium transition-colors cursor-pointer', | |
| filter === id ? 'bg-panel text-fg shadow-xs' : 'text-muted hover:text-fg', | |
| )} | |
| > | |
| {label} | |
| </button> | |
| ))} | |
| </div> | |
| <Button | |
| variant="ghost" | |
| size="sm" | |
| className="h-6.5 px-2 text-[11px]" | |
| disabled={entries.length === 0} | |
| onClick={() => | |
| void onClear() | |
| .then(() => toast.info('Cleared activity log')) | |
| .catch((e) => toast.error(e instanceof Error ? e.message : 'Clear failed')) | |
| } | |
| > | |
| <Trash2 className="h-3 w-3" /> | |
| Clear | |
| </Button> | |
| </div> | |
| {filtered.length === 0 ? ( | |
| <EmptyState | |
| icon={<Activity className="h-5 w-5" />} | |
| title="No matching activity" | |
| description="Protocol calls, captures, stream opens, and polls appear here in real time." | |
| /> | |
| ) : ( | |
| <div className="space-y-1.5"> | |
| {filtered.map((entry) => ( | |
| <div | |
| key={entry.id} | |
| className="flex items-start gap-2 rounded-lg border border-line/80 bg-panel-2/30 px-2.5 py-1.5 text-[11.5px]" | |
| > | |
| <span className="mt-0.5"> | |
| <KindIcon kind={entry.kind} /> | |
| </span> | |
| <div className="min-w-0 flex-1"> | |
| <div className="flex flex-wrap items-center gap-1.5"> | |
| <span className="font-mono text-[10.5px] tabular-nums text-muted-2"> | |
| {formatClock(entry.at)} | |
| </span> | |
| <span className="text-fg">{entry.summary}</span> | |
| {entry.count && entry.count > 1 && ( | |
| <Badge variant="muted" className="font-mono text-[10px] tabular-nums"> | |
| ×{entry.count} | |
| </Badge> | |
| )} | |
| </div> | |
| {entry.client && ( | |
| <div className="font-mono text-[10px] text-muted">{entry.client}</div> | |
| )} | |
| </div> | |
| </div> | |
| ))} | |
| </div> | |
| )} | |
| </div> | |
| ); | |
| } | |