Spaces:
Sleeping
Sleeping
File size: 1,203 Bytes
312fdff | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import type { ConnectionMode } from '../hooks/useLiveMetrics';
interface ConnectionStatusProps {
mode: ConnectionMode;
lastUpdated: Date | null;
error: string | null;
}
const labels: Record<ConnectionMode, string> = {
websocket: 'Live (WebSocket)',
polling: 'Polling (10s)',
connecting: 'Connecting…',
offline: 'Offline',
};
const dotClass: Record<ConnectionMode, string> = {
websocket: 'bg-emerald-400 shadow-emerald-400/50',
polling: 'bg-amber-400 shadow-amber-400/50',
connecting: 'bg-sky-400 animate-pulse',
offline: 'bg-red-400',
};
export function ConnectionStatus({ mode, lastUpdated, error }: ConnectionStatusProps) {
return (
<div className="flex flex-wrap items-center gap-3 text-sm text-[var(--color-text-muted)]">
<span className="inline-flex items-center gap-2 rounded-full border border-[var(--color-border)] bg-[var(--color-surface-raised)] px-3 py-1">
<span className={`h-2 w-2 rounded-full shadow-sm ${dotClass[mode]}`} />
{labels[mode]}
</span>
{lastUpdated && (
<span>Updated {lastUpdated.toLocaleTimeString()}</span>
)}
{error && <span className="text-red-400">{error}</span>}
</div>
);
}
|