From 48ab123850013ce42029919944943359df3da38c Mon Sep 17 00:00:00 2001 From: reya Date: Mon, 4 Dec 2023 09:26:19 +0700 Subject: [PATCH] improve relay screen --- src/app/relays/components/relayEventList.tsx | 30 +++++++++++--------- src/app/relays/components/relayList.tsx | 4 +-- src/app/relays/components/userRelayList.tsx | 25 ++++++++++------ src/shared/accounts/active.tsx | 2 +- 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/app/relays/components/relayEventList.tsx b/src/app/relays/components/relayEventList.tsx index 4f360059..e9249a04 100644 --- a/src/app/relays/components/relayEventList.tsx +++ b/src/app/relays/components/relayEventList.tsx @@ -1,5 +1,6 @@ import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk'; import { useQuery } from '@tanstack/react-query'; +import { normalizeRelayUrl } from 'nostr-fetch'; import { useCallback } from 'react'; import { VList } from 'virtua'; @@ -15,7 +16,7 @@ export function RelayEventList({ relayUrl }: { relayUrl: string }) { queryFn: async () => { const url = 'wss://' + relayUrl; const events = await fetcher.fetchLatestEvents( - [url], + [normalizeRelayUrl(url)], { kinds: [NDKKind.Text, NDKKind.Repost], }, @@ -24,6 +25,8 @@ export function RelayEventList({ relayUrl }: { relayUrl: string }) { return events as unknown as NDKEvent[]; }, refetchOnWindowFocus: false, + refetchOnReconnect: false, + refetchOnMount: false, }); const renderItem = useCallback( @@ -41,19 +44,18 @@ export function RelayEventList({ relayUrl }: { relayUrl: string }) { ); return ( -
- - {status === 'pending' ? ( -
-
- -

Loading newsfeed...

-
+ + {status === 'pending' ? ( +
+
+ +

Loading newsfeed...

- ) : ( - data.map((item) => renderItem(item)) - )} - -
+
+ ) : ( + data.map((item) => renderItem(item)) + )} +
+ ); } diff --git a/src/app/relays/components/relayList.tsx b/src/app/relays/components/relayList.tsx index ec77917a..23861733 100644 --- a/src/app/relays/components/relayList.tsx +++ b/src/app/relays/components/relayList.tsx @@ -9,8 +9,6 @@ import { useNostr } from '@utils/hooks/useNostr'; import { useRelay } from '@utils/hooks/useRelay'; export function RelayList() { - const navigate = useNavigate(); - const { getAllRelaysByUsers } = useNostr(); const { connectRelay } = useRelay(); const { status, data } = useQuery({ @@ -24,6 +22,8 @@ export function RelayList() { staleTime: Infinity, }); + const navigate = useNavigate(); + const inspectRelay = (relayUrl: string) => { const url = new URL(relayUrl); navigate(`/relays/${url.hostname}`); diff --git a/src/app/relays/components/userRelayList.tsx b/src/app/relays/components/userRelayList.tsx index 07d7c383..3afa1235 100644 --- a/src/app/relays/components/userRelayList.tsx +++ b/src/app/relays/components/userRelayList.tsx @@ -6,7 +6,7 @@ import { RelayForm } from '@app/relays/components/relayForm'; import { useNDK } from '@libs/ndk/provider'; import { useStorage } from '@libs/storage/provider'; -import { CancelIcon } from '@shared/icons'; +import { CancelIcon, RefreshIcon } from '@shared/icons'; import { useRelay } from '@utils/hooks/useRelay'; @@ -14,7 +14,7 @@ export function UserRelayList() { const { db } = useStorage(); const { ndk } = useNDK(); const { removeRelay } = useRelay(); - const { status, data } = useQuery({ + const { status, data, refetch } = useQuery({ queryKey: ['relays', db.account.pubkey], queryFn: async () => { const event = await ndk.fetchEvent( @@ -25,7 +25,7 @@ export function UserRelayList() { { cacheUsage: NDKSubscriptionCacheUsage.ONLY_RELAY } ); - if (!event) throw new Error('relay set not found'); + if (!event) return []; return event.tags; }, refetchOnWindowFocus: false, @@ -35,15 +35,22 @@ export function UserRelayList() { return (
-
+

Connected relays

+
{status === 'pending' ? (

Loading...

- ) : !data ? ( -
-

You not have personal relay set yet

+ ) : !data.length ? ( +
+

You not have personal relay list yet

) : ( data.map((item) => ( @@ -68,8 +75,8 @@ export function UserRelayList() {

- {item[2] ? ( -
+ {item[2]?.length ? ( +
{item[2]}
) : null} diff --git a/src/shared/accounts/active.tsx b/src/shared/accounts/active.tsx index e276f289..1d3c6512 100644 --- a/src/shared/accounts/active.tsx +++ b/src/shared/accounts/active.tsx @@ -27,7 +27,7 @@ export function ActiveAccount() { loading="lazy" decoding="async" style={{ contentVisibility: 'auto' }} - className="aspect-square h-auto w-full rounded-md" + className="aspect-square h-auto w-full rounded-md object-cover" />