Files
vega/src/components/feed/RelayStatusBadge.tsx
Jure ac4e39fcbf Add relay status badge, toast notifications, per-tab feed timestamps, relay UX improvements
- Relay status badge in feed header: shows connected/total relay count with
  color coding (green >75%, yellow 25-75%, red <25%), hover tooltip with
  per-relay status
- Toast notification system: transient messages for connection lost,
  reconnecting, relay reset, and back-online events
- Per-tab "last updated" relative timestamp in feed header (global,
  following, trending tracked independently)
- Consolidated all relay management into RelaysView (removed duplicate
  relay section from Settings); per-relay remove button on health cards
- Show all supported NIP badges on relay cards (was filtering to 11 notable)
- Tooltips on relay status dots explaining green/yellow/red/gray meaning
- Fix relay removal with trailing-slash URL normalization
- Fix stale health results lingering after relay removal
- Add acknowledgements section to README
2026-03-23 11:28:53 +01:00

58 lines
1.8 KiB
TypeScript

import { useState } from "react";
import { useRelayStatus } from "../../hooks/useRelayStatus";
function shortenUrl(url: string): string {
return url.replace(/^wss?:\/\//, "").replace(/\/$/, "");
}
export function RelayStatusBadge() {
const { connectedCount, totalCount, relays } = useRelayStatus();
const [hovered, setHovered] = useState(false);
const ratio = totalCount > 0 ? connectedCount / totalCount : 0;
const colorClass =
ratio > 0.75
? "text-success"
: ratio > 0.25
? "text-warning"
: "text-danger";
const dotClass =
ratio > 0.75
? "bg-success"
: ratio > 0.25
? "bg-warning"
: "bg-danger";
if (totalCount === 0) return null;
return (
<span
className={`relative ${colorClass} text-[11px] flex items-center gap-1 cursor-default`}
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
>
<span className={`w-1.5 h-1.5 rounded-full ${dotClass} inline-block`} />
{connectedCount}/{totalCount} relays
{hovered && (
<div className="absolute right-0 top-full mt-1 bg-bg-raised border border-border p-2 z-50 min-w-[200px] shadow-lg">
{relays
.sort((a, b) => (a.connected === b.connected ? 0 : a.connected ? -1 : 1))
.map((r) => (
<div key={r.url} className="flex items-center gap-2 py-0.5">
<span
className={`w-1.5 h-1.5 rounded-full shrink-0 ${
r.connected ? "bg-success" : "bg-danger"
}`}
/>
<span className="text-[11px] text-text-dim truncate">
{shortenUrl(r.url)}
</span>
</div>
))}
</div>
)}
</span>
);
}