Spaces:
Running
Running
File size: 4,595 Bytes
6f5f15e | 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | import { Copy, Heart, PlugZap, ShieldBan } from 'lucide-react';
import { toast } from 'sonner';
import type { PushStreamView } from '../../../shared/api-types';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
import { formatMs, formatUptime, prettyCursor } from '@/lib/format';
import { ClientBadge } from './ClientBadge';
import { EraBadge } from './EraBadge';
export function PushStreamRow({
stream,
nowMs,
heartbeatSeq,
onDrop,
onRevoke,
}: {
stream: PushStreamView;
nowMs: number;
heartbeatSeq: number;
onDrop: (streamId: string) => Promise<void>;
onRevoke: (streamId: string) => Promise<void>;
}) {
const copyCursor = async () => {
if (!stream.cursor) return;
try {
await navigator.clipboard.writeText(stream.cursor);
toast.success('Copied stream cursor');
} catch {
toast.error('Clipboard copy failed');
}
};
return (
<div className="rounded-lg border border-push/25 bg-panel-2/45 p-2.5 space-y-2">
<div className="flex items-start justify-between gap-2">
<div className="min-w-0 space-y-1">
<div className="flex flex-wrap items-center gap-1.5">
<span className="h-2 w-2 rounded-full bg-push shrink-0" />
<ClientBadge client={stream.client} />
<EraBadge era={stream.client.era} protocolVersion={stream.client.protocolVersion} />
</div>
<div className="flex flex-wrap items-center gap-1.5">
<Badge variant="event" className="font-mono text-[10px]">
{stream.eventName}
</Badge>
<button
type="button"
onClick={() => void copyCursor()}
className="inline-flex items-center gap-1 font-mono text-[10.5px] text-muted hover:text-fg cursor-pointer"
title={stream.cursor ? `Copy cursor ${stream.cursor}` : 'No cursor'}
>
<span>cur:{prettyCursor(stream.cursor)}</span>
{stream.cursor && <Copy className="h-2.5 w-2.5 opacity-60" />}
</button>
</div>
</div>
<div className="flex items-center gap-1 shrink-0">
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="outline"
size="sm"
className="h-6.5 px-2 text-[11px]"
onClick={() =>
void onDrop(stream.streamId)
.then(() => toast.info('Dropped push stream (graceful close)'))
.catch((e) => toast.error(e instanceof Error ? e.message : 'Drop failed'))
}
>
<PlugZap className="h-3 w-3" />
Drop
</Button>
</TooltipTrigger>
<TooltipContent>Close gracefully; client reconnects from its cursor</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="danger"
size="sm"
className="h-6.5 px-2 text-[11px]"
onClick={() =>
void onRevoke(stream.streamId)
.then(() => toast.warning('Revoked push stream (-32024 Forbidden)'))
.catch((e) => toast.error(e instanceof Error ? e.message : 'Revoke failed'))
}
>
<ShieldBan className="h-3 w-3" />
Revoke
</Button>
</TooltipTrigger>
<TooltipContent>Send terminated / -32024 Forbidden so client removes subscription</TooltipContent>
</Tooltip>
</div>
</div>
<div className="flex flex-wrap items-center gap-3 text-[11px] text-muted tabular-nums">
<span className="relative inline-flex items-center gap-1 text-push">
<span className="relative flex h-3.5 w-3.5 items-center justify-center">
{heartbeatSeq > 0 && (
<span
key={heartbeatSeq}
className="animate-heartbeat-ring absolute inset-0 rounded-full border border-push"
/>
)}
<Heart className="h-3 w-3 fill-current" />
</span>
<span>{formatMs(stream.heartbeatMs)}</span>
</span>
<span>up {formatUptime(stream.openedAt, nowMs)}</span>
<span>
delivered <strong className="font-medium text-fg">{stream.delivered}</strong>
</span>
</div>
</div>
);
}
|