fix: 🐛

This commit is contained in:
codytseng
2024-12-24 13:08:40 +08:00
parent 31f70c2ab1
commit b5174df32c
4 changed files with 19 additions and 11 deletions

View File

@@ -4,20 +4,27 @@ import client from '@/services/client.service'
export function useFetchRelayList(pubkey?: string | null) { export function useFetchRelayList(pubkey?: string | null) {
const [relayList, setRelayList] = useState<TRelayList>({ write: [], read: [] }) const [relayList, setRelayList] = useState<TRelayList>({ write: [], read: [] })
const [isFetching, setIsFetching] = useState(true)
useEffect(() => { useEffect(() => {
const fetchRelayList = async () => { const fetchRelayList = async () => {
if (!pubkey) return setIsFetching(true)
if (!pubkey) {
setIsFetching(false)
return
}
try { try {
const relayList = await client.fetchRelayList(pubkey) const relayList = await client.fetchRelayList(pubkey)
setRelayList(relayList) setRelayList(relayList)
} catch (err) { } catch (err) {
console.error(err) console.error(err)
} finally {
setIsFetching(false)
} }
} }
fetchRelayList() fetchRelayList()
}, [pubkey]) }, [pubkey])
return relayList return { relayList, isFetching }
} }

View File

@@ -11,8 +11,8 @@ import SecondaryPageLayout from '@/layouts/SecondaryPageLayout'
import { getParentEventId, getRootEventId } from '@/lib/event' import { getParentEventId, getRootEventId } from '@/lib/event'
import { toNote } from '@/lib/link' import { toNote } from '@/lib/link'
import { useMemo } from 'react' import { useMemo } from 'react'
import NotFoundPage from '../NotFoundPage'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import NotFoundPage from '../NotFoundPage'
export default function NotePage({ id }: { id?: string }) { export default function NotePage({ id }: { id?: string }) {
const { t } = useTranslation() const { t } = useTranslation()

View File

@@ -24,7 +24,7 @@ import QrCodePopover from './QrCodePopover'
export default function ProfilePage({ id }: { id?: string }) { export default function ProfilePage({ id }: { id?: string }) {
const { t } = useTranslation() const { t } = useTranslation()
const { profile, isFetching } = useFetchProfile(id) const { profile, isFetching } = useFetchProfile(id)
const relayList = useFetchRelayList(profile?.pubkey) const { relayList, isFetching: isFetchingRelayInfo } = useFetchRelayList(profile?.pubkey)
const { relayUrls: currentRelayUrls } = useRelaySettings() const { relayUrls: currentRelayUrls } = useRelaySettings()
const { pubkey: accountPubkey } = useNostr() const { pubkey: accountPubkey } = useNostr()
const { followings: selfFollowings } = useFollowList() const { followings: selfFollowings } = useFollowList()
@@ -99,12 +99,13 @@ export default function ProfilePage({ id }: { id?: string }) {
</div> </div>
</div> </div>
<Separator className="hidden sm:block mt-4 sm:my-4" /> <Separator className="hidden sm:block mt-4 sm:my-4" />
<NoteList {!isFetchingRelayInfo && (
key={pubkey} <NoteList
filter={{ authors: [pubkey] }} filter={{ authors: [pubkey] }}
relayUrls={relayList.write.slice(0, 5).concat(currentRelayUrls)} relayUrls={relayList.write.slice(0, 5).concat(currentRelayUrls)}
className="max-sm:mt-2" className="max-sm:mt-2"
/> />
)}
</SecondaryPageLayout> </SecondaryPageLayout>
) )
} }

View File

@@ -46,7 +46,7 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
const [signer, setSigner] = useState<ISigner | null>(null) const [signer, setSigner] = useState<ISigner | null>(null)
const [openLoginDialog, setOpenLoginDialog] = useState(false) const [openLoginDialog, setOpenLoginDialog] = useState(false)
const { relayUrls: currentRelayUrls } = useRelaySettings() const { relayUrls: currentRelayUrls } = useRelaySettings()
const relayList = useFetchRelayList(account?.pubkey) const { relayList } = useFetchRelayList(account?.pubkey)
useEffect(() => { useEffect(() => {
const init = async () => { const init = async () => {