import { useQuery, useQueryClient } from '@tanstack/react-query'; import { message } from '@tauri-apps/plugin-dialog'; import { normalizeRelayUrl } from 'nostr-fetch'; import { useNavigate } from 'react-router-dom'; 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( ['relays'], 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) await message("You're aldready connected to this relay"); queryClient.invalidateQueries(['user-relay']); }; return (
{status === 'loading' ? (

Loading relay...

) : (

All relays used by your follows

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