fix: 🐛

This commit is contained in:
codytseng
2025-08-12 11:05:24 +08:00
parent c6a5157fe7
commit 4a946e4ab0
9 changed files with 310 additions and 211 deletions

View File

@@ -0,0 +1,99 @@
import NoteList, { TNoteListRef } from '@/components/NoteList'
import Tabs from '@/components/Tabs'
import { BIG_RELAY_URLS } from '@/constants'
import { useNostr } from '@/providers/NostrProvider'
import client from '@/services/client.service'
import storage from '@/services/local-storage.service'
import { TFeedSubRequest, TNoteListMode } from '@/types'
import { useEffect, useMemo, useRef, useState } from 'react'
export default function ProfileFeed({
pubkey,
topSpace = 0
}: {
pubkey: string
topSpace?: number
}) {
const { pubkey: myPubkey } = useNostr()
const [listMode, setListMode] = useState<TNoteListMode>(() => storage.getNoteListMode())
const noteListRef = useRef<TNoteListRef>(null)
const [subRequests, setSubRequests] = useState<TFeedSubRequest[]>([])
const tabs = useMemo(() => {
const _tabs = [
{ value: 'posts', label: 'Notes' },
{ value: 'postsAndReplies', label: 'Replies' }
]
if (myPubkey && myPubkey !== pubkey) {
_tabs.push({ value: 'you', label: 'YouTabName' })
}
return _tabs
}, [myPubkey, pubkey])
useEffect(() => {
const init = async () => {
if (listMode === 'you') {
if (!myPubkey) {
setSubRequests([])
return
}
const [relayList, myRelayList] = await Promise.all([
client.fetchRelayList(pubkey),
client.fetchRelayList(myPubkey)
])
setSubRequests([
{
urls: myRelayList.write.concat(BIG_RELAY_URLS).slice(0, 5),
filter: {
authors: [myPubkey],
'#p': [pubkey]
}
},
{
urls: relayList.write.concat(BIG_RELAY_URLS).slice(0, 5),
filter: {
authors: [pubkey],
'#p': [myPubkey]
}
}
])
return
}
const relayList = await client.fetchRelayList(pubkey)
setSubRequests([
{
urls: relayList.write.concat(BIG_RELAY_URLS).slice(0, 8),
filter: {
authors: [pubkey]
}
}
])
}
init()
}, [pubkey, listMode])
const handleListModeChange = (mode: TNoteListMode) => {
setListMode(mode)
setTimeout(() => {
noteListRef.current?.scrollToTop()
}, 0)
}
return (
<>
<Tabs
value={listMode}
tabs={tabs}
onTabChange={(listMode) => {
handleListModeChange(listMode as TNoteListMode)
}}
threshold={Math.max(800, topSpace)}
/>
<NoteList ref={noteListRef} subRequests={subRequests} hideReplies={listMode === 'posts'} />
</>
)
}