mirror of
https://github.com/hoornet/vega.git
synced 2026-05-07 04:39:12 -07:00
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
This commit is contained in:
37
src/hooks/useRelayStatus.ts
Normal file
37
src/hooks/useRelayStatus.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { getNDK } from "../lib/nostr";
|
||||
|
||||
interface RelayInfo {
|
||||
url: string;
|
||||
connected: boolean;
|
||||
}
|
||||
|
||||
interface RelayStatus {
|
||||
connectedCount: number;
|
||||
totalCount: number;
|
||||
relays: RelayInfo[];
|
||||
}
|
||||
|
||||
function readPool(): RelayStatus {
|
||||
const ndk = getNDK();
|
||||
const relays = Array.from(ndk.pool?.relays?.values() ?? []).map((r) => ({
|
||||
url: r.url,
|
||||
connected: r.connected,
|
||||
}));
|
||||
return {
|
||||
connectedCount: relays.filter((r) => r.connected).length,
|
||||
totalCount: relays.length,
|
||||
relays,
|
||||
};
|
||||
}
|
||||
|
||||
export function useRelayStatus(): RelayStatus {
|
||||
const [status, setStatus] = useState<RelayStatus>(readPool);
|
||||
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => setStatus(readPool()), 5000);
|
||||
return () => clearInterval(id);
|
||||
}, []);
|
||||
|
||||
return status;
|
||||
}
|
||||
Reference in New Issue
Block a user