Browse Source

fix: 🐛

imwald
codytseng 1 year ago
parent
commit
b5174df32c
  1. 11
      src/hooks/useFetchRelayList.tsx
  2. 2
      src/pages/secondary/NotePage/index.tsx
  3. 15
      src/pages/secondary/ProfilePage/index.tsx
  4. 2
      src/providers/NostrProvider/index.tsx

11
src/hooks/useFetchRelayList.tsx

@ -4,20 +4,27 @@ import client from '@/services/client.service' @@ -4,20 +4,27 @@ import client from '@/services/client.service'
export function useFetchRelayList(pubkey?: string | null) {
const [relayList, setRelayList] = useState<TRelayList>({ 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 }
}

2
src/pages/secondary/NotePage/index.tsx

@ -11,8 +11,8 @@ import SecondaryPageLayout from '@/layouts/SecondaryPageLayout' @@ -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()

15
src/pages/secondary/ProfilePage/index.tsx

@ -24,7 +24,7 @@ import QrCodePopover from './QrCodePopover' @@ -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 }) { @@ -99,12 +99,13 @@ export default function ProfilePage({ id }: { id?: string }) {
</div>
</div>
<Separator className="hidden sm:block mt-4 sm:my-4" />
<NoteList
key={pubkey}
filter={{ authors: [pubkey] }}
relayUrls={relayList.write.slice(0, 5).concat(currentRelayUrls)}
className="max-sm:mt-2"
/>
{!isFetchingRelayInfo && (
<NoteList
filter={{ authors: [pubkey] }}
relayUrls={relayList.write.slice(0, 5).concat(currentRelayUrls)}
className="max-sm:mt-2"
/>
)}
</SecondaryPageLayout>
)
}

2
src/providers/NostrProvider/index.tsx

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

Loading…
Cancel
Save