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 ; if (kind.startsWith('stream.')) { return kind === 'stream.error' || kind === 'stream.revoked' ? ( ) : ( ); } if (kind === 'poll' || kind === 'poll.error') { return kind === 'poll.error' ? ( ) : ( ); } if (kind === 'call') return ; if (kind === 'capture' || kind === 'capture.error') { return ( ); } if (kind === 'config') return ; return ; } export function ActivityFeed({ entries, onClear, }: { entries: ActivityEntry[]; onClear: () => Promise; }) { const [filter, setFilter] = useState('all'); const filtered = entries.filter((e) => matchesFilter(e.kind, filter)); return (
{( [ ['all', 'All'], ['events', 'Events'], ['subscriptions', 'Subscriptions'], ['calls', 'Calls'], ] as const ).map(([id, label]) => ( ))}
{filtered.length === 0 ? ( } title="No matching activity" description="Protocol calls, captures, stream opens, and polls appear here in real time." /> ) : (
{filtered.map((entry) => (
{formatClock(entry.at)} {entry.summary} {entry.count && entry.count > 1 && ( ×{entry.count} )}
{entry.client && (
{entry.client}
)}
))}
)}
); }