diff --git a/src/hooks/useFetchRelayList.tsx b/src/hooks/useFetchRelayList.tsx index 8d36369e..1de44f62 100644 --- a/src/hooks/useFetchRelayList.tsx +++ b/src/hooks/useFetchRelayList.tsx @@ -4,20 +4,27 @@ import client from '@/services/client.service' export function useFetchRelayList(pubkey?: string | null) { const [relayList, setRelayList] = useState({ write: [], read: [] }) + const [isFetching, setIsFetching] = useState(true) useEffect(() => { const fetchRelayList = async () => { - if (!pubkey) return + setIsFetching(true) + if (!pubkey) { + setIsFetching(false) + return + } try { const relayList = await client.fetchRelayList(pubkey) setRelayList(relayList) } catch (err) { console.error(err) + } finally { + setIsFetching(false) } } fetchRelayList() }, [pubkey]) - return relayList + return { relayList, isFetching } } diff --git a/src/pages/secondary/NotePage/index.tsx b/src/pages/secondary/NotePage/index.tsx index 88f71a29..70fdc1d6 100644 --- a/src/pages/secondary/NotePage/index.tsx +++ b/src/pages/secondary/NotePage/index.tsx @@ -11,8 +11,8 @@ import SecondaryPageLayout from '@/layouts/SecondaryPageLayout' import { getParentEventId, getRootEventId } from '@/lib/event' import { toNote } from '@/lib/link' import { useMemo } from 'react' -import NotFoundPage from '../NotFoundPage' import { useTranslation } from 'react-i18next' +import NotFoundPage from '../NotFoundPage' export default function NotePage({ id }: { id?: string }) { const { t } = useTranslation() diff --git a/src/pages/secondary/ProfilePage/index.tsx b/src/pages/secondary/ProfilePage/index.tsx index 894e073e..2cee9bd9 100644 --- a/src/pages/secondary/ProfilePage/index.tsx +++ b/src/pages/secondary/ProfilePage/index.tsx @@ -24,7 +24,7 @@ import QrCodePopover from './QrCodePopover' export default function ProfilePage({ id }: { id?: string }) { const { t } = useTranslation() const { profile, isFetching } = useFetchProfile(id) - const relayList = useFetchRelayList(profile?.pubkey) + const { relayList, isFetching: isFetchingRelayInfo } = useFetchRelayList(profile?.pubkey) const { relayUrls: currentRelayUrls } = useRelaySettings() const { pubkey: accountPubkey } = useNostr() const { followings: selfFollowings } = useFollowList() @@ -99,12 +99,13 @@ export default function ProfilePage({ id }: { id?: string }) { - + {!isFetchingRelayInfo && ( + + )} ) } diff --git a/src/providers/NostrProvider/index.tsx b/src/providers/NostrProvider/index.tsx index e723437f..4f9390ee 100644 --- a/src/providers/NostrProvider/index.tsx +++ b/src/providers/NostrProvider/index.tsx @@ -46,7 +46,7 @@ export function NostrProvider({ children }: { children: React.ReactNode }) { const [signer, setSigner] = useState(null) const [openLoginDialog, setOpenLoginDialog] = useState(false) const { relayUrls: currentRelayUrls } = useRelaySettings() - const relayList = useFetchRelayList(account?.pubkey) + const { relayList } = useFetchRelayList(account?.pubkey) useEffect(() => { const init = async () => {