import { useQuery, useQueryClient } from '@tanstack/react-query'; import { normalizeRelayUrl } from 'nostr-fetch'; import { useNavigate } from 'react-router-dom'; import { toast } from 'sonner'; import { VList } from 'virtua'; import { useStorage } from '@libs/storage/provider'; import { LoaderIcon, PlusIcon, ShareIcon } from '@shared/icons'; import { User } from '@shared/user'; import { useNostr } from '@utils/hooks/useNostr'; export function RelayList() { const navigate = useNavigate(); const queryClient = useQueryClient(); const { getAllRelaysByUsers } = useNostr(); const { db } = useStorage(); const { status, data } = useQuery({ queryKey: ['relays'], queryFn: async () => { return await getAllRelaysByUsers(); }, refetchOnWindowFocus: false, refetchOnMount: false, refetchOnReconnect: false, staleTime: Infinity, }); const inspectRelay = (relayUrl: string) => { const url = new URL(relayUrl); navigate(`/relays/${url.hostname}`); }; const connectRelay = async (relayUrl: string) => { const url = normalizeRelayUrl(relayUrl); const res = await db.createRelay(url); if (res) { toast.info('Connected. You need to restart app to take effect'); queryClient.invalidateQueries({ queryKey: ['user-relay'], }); } else { toast.warning("You're aldready connected to this relay"); } }; return (
{status === 'pending' ? (

Loading relay...

) : (

All relays

{[...data].map(([key, value]) => (
Relay:{' '} {key}
{value.slice(0, 4).map((item) => ( ))} {value.length > 4 ? (
+{value.length}
) : null}
))}
)}
); }