fix: 🐛
This commit is contained in:
@@ -1,135 +1,28 @@
|
|||||||
import NoteList, { TNoteListRef } from '@/components/NoteList'
|
import NoteList, { TNoteListRef } from '@/components/NoteList'
|
||||||
import Tabs from '@/components/Tabs'
|
import Tabs from '@/components/Tabs'
|
||||||
import { ExtendedKind } from '@/constants'
|
|
||||||
import { isReplyNoteEvent } from '@/lib/event'
|
|
||||||
import { useNostr } from '@/providers/NostrProvider'
|
|
||||||
import { useUserTrust } from '@/providers/UserTrustProvider'
|
import { useUserTrust } from '@/providers/UserTrustProvider'
|
||||||
import client from '@/services/client.service'
|
|
||||||
import storage from '@/services/local-storage.service'
|
import storage from '@/services/local-storage.service'
|
||||||
import { TNormalFeedSubRequest, TNoteListMode } from '@/types'
|
import { TFeedSubRequest, TNoteListMode } from '@/types'
|
||||||
import dayjs from 'dayjs'
|
import { useRef, useState } from 'react'
|
||||||
import { Event, kinds } from 'nostr-tools'
|
|
||||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
||||||
|
|
||||||
const LIMIT = 100
|
|
||||||
const ALGO_LIMIT = 500
|
|
||||||
const KINDS = [
|
|
||||||
kinds.ShortTextNote,
|
|
||||||
kinds.Repost,
|
|
||||||
kinds.Highlights,
|
|
||||||
kinds.LongFormArticle,
|
|
||||||
ExtendedKind.COMMENT,
|
|
||||||
ExtendedKind.POLL,
|
|
||||||
ExtendedKind.VOICE,
|
|
||||||
ExtendedKind.VOICE_COMMENT,
|
|
||||||
ExtendedKind.PICTURE
|
|
||||||
]
|
|
||||||
|
|
||||||
export default function NormalFeed({
|
export default function NormalFeed({
|
||||||
subRequests,
|
subRequests,
|
||||||
areAlgoRelays = false
|
areAlgoRelays = false,
|
||||||
|
isMainFeed = false
|
||||||
}: {
|
}: {
|
||||||
subRequests: TNormalFeedSubRequest[]
|
subRequests: TFeedSubRequest[]
|
||||||
areAlgoRelays?: boolean
|
areAlgoRelays?: boolean
|
||||||
|
isMainFeed?: boolean
|
||||||
}) {
|
}) {
|
||||||
const { startLogin } = useNostr()
|
const { hideUntrustedNotes } = useUserTrust()
|
||||||
const { isUserTrusted, hideUntrustedNotes } = useUserTrust()
|
|
||||||
const [listMode, setListMode] = useState<TNoteListMode>(() => storage.getNoteListMode())
|
const [listMode, setListMode] = useState<TNoteListMode>(() => storage.getNoteListMode())
|
||||||
const [events, setEvents] = useState<Event[]>([])
|
|
||||||
const [newEvents, setNewEvents] = useState<Event[]>([])
|
|
||||||
const [hasMore, setHasMore] = useState<boolean>(true)
|
|
||||||
const [loading, setLoading] = useState(true)
|
|
||||||
const [timelineKey, setTimelineKey] = useState<string | undefined>(undefined)
|
|
||||||
const [refreshCount, setRefreshCount] = useState(0)
|
|
||||||
const noteListRef = useRef<TNoteListRef>(null)
|
const noteListRef = useRef<TNoteListRef>(null)
|
||||||
const filteredNewEvents = useMemo(() => {
|
|
||||||
return newEvents.filter((event: Event) => {
|
|
||||||
return (
|
|
||||||
(listMode !== 'posts' || !isReplyNoteEvent(event)) &&
|
|
||||||
(!hideUntrustedNotes || isUserTrusted(event.pubkey))
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}, [newEvents, listMode, hideUntrustedNotes])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!subRequests.length) return
|
|
||||||
|
|
||||||
async function init() {
|
|
||||||
setLoading(true)
|
|
||||||
setEvents([])
|
|
||||||
setNewEvents([])
|
|
||||||
setHasMore(true)
|
|
||||||
|
|
||||||
const { closer, timelineKey } = await client.subscribeTimeline(
|
|
||||||
subRequests.map(({ urls, filter }) => ({
|
|
||||||
urls,
|
|
||||||
filter: {
|
|
||||||
...filter,
|
|
||||||
kinds: KINDS,
|
|
||||||
limit: areAlgoRelays ? ALGO_LIMIT : LIMIT
|
|
||||||
}
|
|
||||||
})),
|
|
||||||
{
|
|
||||||
onEvents: (events, eosed) => {
|
|
||||||
if (events.length > 0) {
|
|
||||||
setEvents(events)
|
|
||||||
}
|
|
||||||
if (areAlgoRelays) {
|
|
||||||
setHasMore(false)
|
|
||||||
}
|
|
||||||
if (eosed) {
|
|
||||||
setLoading(false)
|
|
||||||
setHasMore(events.length > 0)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onNew: (event) => {
|
|
||||||
setNewEvents((oldEvents) =>
|
|
||||||
[event, ...oldEvents].sort((a, b) => b.created_at - a.created_at)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
startLogin,
|
|
||||||
needSort: !areAlgoRelays
|
|
||||||
}
|
|
||||||
)
|
|
||||||
setTimelineKey(timelineKey)
|
|
||||||
return closer
|
|
||||||
}
|
|
||||||
|
|
||||||
const promise = init()
|
|
||||||
return () => {
|
|
||||||
promise.then((closer) => closer())
|
|
||||||
}
|
|
||||||
}, [JSON.stringify(subRequests), refreshCount])
|
|
||||||
|
|
||||||
const loadMore = async () => {
|
|
||||||
if (!timelineKey || areAlgoRelays) return
|
|
||||||
setLoading(true)
|
|
||||||
const newEvents = await client.loadMoreTimeline(
|
|
||||||
timelineKey,
|
|
||||||
events.length ? events[events.length - 1].created_at - 1 : dayjs().unix(),
|
|
||||||
LIMIT
|
|
||||||
)
|
|
||||||
setLoading(false)
|
|
||||||
if (newEvents.length === 0) {
|
|
||||||
setHasMore(false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
setEvents((oldEvents) => [...oldEvents, ...newEvents])
|
|
||||||
}
|
|
||||||
|
|
||||||
const showNewEvents = () => {
|
|
||||||
setEvents((oldEvents) => [...newEvents, ...oldEvents])
|
|
||||||
setNewEvents([])
|
|
||||||
setTimeout(() => {
|
|
||||||
noteListRef.current?.scrollToTop()
|
|
||||||
}, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleListModeChange = (mode: TNoteListMode) => {
|
const handleListModeChange = (mode: TNoteListMode) => {
|
||||||
setListMode(mode)
|
setListMode(mode)
|
||||||
storage.setNoteListMode(mode)
|
if (isMainFeed) {
|
||||||
|
storage.setNoteListMode(mode)
|
||||||
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
noteListRef.current?.scrollToTop()
|
noteListRef.current?.scrollToTop()
|
||||||
}, 0)
|
}, 0)
|
||||||
@@ -149,19 +42,10 @@ export default function NormalFeed({
|
|||||||
/>
|
/>
|
||||||
<NoteList
|
<NoteList
|
||||||
ref={noteListRef}
|
ref={noteListRef}
|
||||||
events={events.filter(
|
subRequests={subRequests}
|
||||||
(event: Event) =>
|
hideReplies={listMode === 'posts'}
|
||||||
(listMode !== 'posts' || !isReplyNoteEvent(event)) &&
|
hideUntrustedNotes={hideUntrustedNotes}
|
||||||
(!hideUntrustedNotes || isUserTrusted(event.pubkey))
|
areAlgoRelays={areAlgoRelays}
|
||||||
)}
|
|
||||||
hasMore={hasMore}
|
|
||||||
loading={loading}
|
|
||||||
loadMore={loadMore}
|
|
||||||
onRefresh={() => {
|
|
||||||
setRefreshCount((count) => count + 1)
|
|
||||||
}}
|
|
||||||
newEvents={filteredNewEvents}
|
|
||||||
showNewEvents={showNewEvents}
|
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,53 +1,162 @@
|
|||||||
import NewNotesButton from '@/components/NewNotesButton'
|
import NewNotesButton from '@/components/NewNotesButton'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { getReplaceableCoordinateFromEvent, isReplaceableEvent } from '@/lib/event'
|
import { ExtendedKind } from '@/constants'
|
||||||
import { Event } from 'nostr-tools'
|
import {
|
||||||
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react'
|
getReplaceableCoordinateFromEvent,
|
||||||
|
isReplaceableEvent,
|
||||||
|
isReplyNoteEvent
|
||||||
|
} from '@/lib/event'
|
||||||
|
import { useMuteList } from '@/providers/MuteListProvider'
|
||||||
|
import { useNostr } from '@/providers/NostrProvider'
|
||||||
|
import { useUserTrust } from '@/providers/UserTrustProvider'
|
||||||
|
import client from '@/services/client.service'
|
||||||
|
import { TFeedSubRequest } from '@/types'
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
import { Event, kinds } from 'nostr-tools'
|
||||||
|
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import PullToRefresh from 'react-simple-pull-to-refresh'
|
import PullToRefresh from 'react-simple-pull-to-refresh'
|
||||||
import NoteCard, { NoteCardLoadingSkeleton } from '../NoteCard'
|
import NoteCard, { NoteCardLoadingSkeleton } from '../NoteCard'
|
||||||
|
|
||||||
|
const LIMIT = 100
|
||||||
|
const ALGO_LIMIT = 500
|
||||||
|
const KINDS = [
|
||||||
|
kinds.ShortTextNote,
|
||||||
|
kinds.Repost,
|
||||||
|
kinds.Highlights,
|
||||||
|
kinds.LongFormArticle,
|
||||||
|
ExtendedKind.COMMENT,
|
||||||
|
ExtendedKind.POLL,
|
||||||
|
ExtendedKind.VOICE,
|
||||||
|
ExtendedKind.VOICE_COMMENT,
|
||||||
|
ExtendedKind.PICTURE
|
||||||
|
]
|
||||||
|
|
||||||
const SHOW_COUNT = 10
|
const SHOW_COUNT = 10
|
||||||
|
|
||||||
const NoteList = forwardRef(
|
const NoteList = forwardRef(
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
events,
|
subRequests,
|
||||||
hasMore,
|
filterMutedNotes = true,
|
||||||
loading,
|
hideReplies = false,
|
||||||
loadMore,
|
hideUntrustedNotes = false,
|
||||||
newEvents = [],
|
areAlgoRelays = false
|
||||||
showNewEvents,
|
|
||||||
onRefresh,
|
|
||||||
filterMutedNotes
|
|
||||||
}: {
|
}: {
|
||||||
events: Event[]
|
subRequests: TFeedSubRequest[]
|
||||||
hasMore: boolean
|
|
||||||
loading: boolean
|
|
||||||
loadMore?: () => void
|
|
||||||
newEvents?: Event[]
|
|
||||||
showNewEvents?: () => void
|
|
||||||
onRefresh?: () => void
|
|
||||||
filterMutedNotes?: boolean
|
filterMutedNotes?: boolean
|
||||||
|
hideReplies?: boolean
|
||||||
|
hideUntrustedNotes?: boolean
|
||||||
|
areAlgoRelays?: boolean
|
||||||
},
|
},
|
||||||
ref
|
ref
|
||||||
) => {
|
) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const { startLogin } = useNostr()
|
||||||
|
const { isUserTrusted } = useUserTrust()
|
||||||
|
const { mutePubkeys } = useMuteList()
|
||||||
|
const [events, setEvents] = useState<Event[]>([])
|
||||||
|
const [newEvents, setNewEvents] = useState<Event[]>([])
|
||||||
|
const [hasMore, setHasMore] = useState<boolean>(true)
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [timelineKey, setTimelineKey] = useState<string | undefined>(undefined)
|
||||||
|
const [refreshCount, setRefreshCount] = useState(0)
|
||||||
const [showCount, setShowCount] = useState(SHOW_COUNT)
|
const [showCount, setShowCount] = useState(SHOW_COUNT)
|
||||||
const bottomRef = useRef<HTMLDivElement | null>(null)
|
const bottomRef = useRef<HTMLDivElement | null>(null)
|
||||||
const topRef = useRef<HTMLDivElement | null>(null)
|
const topRef = useRef<HTMLDivElement | null>(null)
|
||||||
|
|
||||||
useImperativeHandle(
|
const filteredEvents = useMemo(() => {
|
||||||
ref,
|
const idSet = new Set<string>()
|
||||||
() => ({
|
|
||||||
scrollToTop: () => {
|
|
||||||
topRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
[]
|
|
||||||
)
|
|
||||||
|
|
||||||
const idSet = new Set<string>()
|
return events.slice(0, showCount).filter((evt) => {
|
||||||
|
if (hideReplies && isReplyNoteEvent(evt)) return false
|
||||||
|
if (hideUntrustedNotes && !isUserTrusted(evt.pubkey)) return false
|
||||||
|
|
||||||
|
const id = isReplaceableEvent(evt.kind) ? getReplaceableCoordinateFromEvent(evt) : evt.id
|
||||||
|
if (idSet.has(id)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
idSet.add(id)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}, [events, hideReplies, hideUntrustedNotes, showCount])
|
||||||
|
|
||||||
|
const filteredNewEvents = useMemo(() => {
|
||||||
|
const idSet = new Set<string>()
|
||||||
|
|
||||||
|
return newEvents.filter((event: Event) => {
|
||||||
|
if (hideReplies && isReplyNoteEvent(event)) return false
|
||||||
|
if (hideUntrustedNotes && !isUserTrusted(event.pubkey)) return false
|
||||||
|
if (filterMutedNotes && mutePubkeys.includes(event.pubkey)) return false
|
||||||
|
|
||||||
|
const id = isReplaceableEvent(event.kind)
|
||||||
|
? getReplaceableCoordinateFromEvent(event)
|
||||||
|
: event.id
|
||||||
|
if (idSet.has(id)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
idSet.add(id)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}, [newEvents, hideReplies, hideUntrustedNotes, filterMutedNotes, mutePubkeys])
|
||||||
|
|
||||||
|
const scrollToTop = () => {
|
||||||
|
topRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||||
|
}
|
||||||
|
|
||||||
|
useImperativeHandle(ref, () => ({ scrollToTop }), [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!subRequests.length) return
|
||||||
|
|
||||||
|
async function init() {
|
||||||
|
setLoading(true)
|
||||||
|
setEvents([])
|
||||||
|
setNewEvents([])
|
||||||
|
setHasMore(true)
|
||||||
|
|
||||||
|
const { closer, timelineKey } = await client.subscribeTimeline(
|
||||||
|
subRequests.map(({ urls, filter }) => ({
|
||||||
|
urls,
|
||||||
|
filter: {
|
||||||
|
...filter,
|
||||||
|
kinds: KINDS,
|
||||||
|
limit: areAlgoRelays ? ALGO_LIMIT : LIMIT
|
||||||
|
}
|
||||||
|
})),
|
||||||
|
{
|
||||||
|
onEvents: (events, eosed) => {
|
||||||
|
if (events.length > 0) {
|
||||||
|
setEvents(events)
|
||||||
|
}
|
||||||
|
if (areAlgoRelays) {
|
||||||
|
setHasMore(false)
|
||||||
|
}
|
||||||
|
if (eosed) {
|
||||||
|
setLoading(false)
|
||||||
|
setHasMore(events.length > 0)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onNew: (event) => {
|
||||||
|
setNewEvents((oldEvents) =>
|
||||||
|
[event, ...oldEvents].sort((a, b) => b.created_at - a.created_at)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
startLogin,
|
||||||
|
needSort: !areAlgoRelays
|
||||||
|
}
|
||||||
|
)
|
||||||
|
setTimelineKey(timelineKey)
|
||||||
|
return closer
|
||||||
|
}
|
||||||
|
|
||||||
|
const promise = init()
|
||||||
|
return () => {
|
||||||
|
promise.then((closer) => closer())
|
||||||
|
}
|
||||||
|
}, [JSON.stringify(subRequests), refreshCount])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const options = {
|
const options = {
|
||||||
@@ -56,22 +165,33 @@ const NoteList = forwardRef(
|
|||||||
threshold: 0.1
|
threshold: 0.1
|
||||||
}
|
}
|
||||||
|
|
||||||
const _loadMore = async () => {
|
const loadMore = async () => {
|
||||||
if (showCount < events.length) {
|
if (showCount < events.length) {
|
||||||
setShowCount((prev) => prev + SHOW_COUNT)
|
setShowCount((prev) => prev + SHOW_COUNT)
|
||||||
// preload more
|
// preload more
|
||||||
if (events.length - showCount > 2 * SHOW_COUNT) {
|
if (events.length - showCount > SHOW_COUNT * 5) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loading || !hasMore) return
|
if (!timelineKey || loading || !hasMore) return
|
||||||
loadMore?.()
|
setLoading(true)
|
||||||
|
const newEvents = await client.loadMoreTimeline(
|
||||||
|
timelineKey,
|
||||||
|
events.length ? events[events.length - 1].created_at - 1 : dayjs().unix(),
|
||||||
|
LIMIT
|
||||||
|
)
|
||||||
|
setLoading(false)
|
||||||
|
if (newEvents.length === 0) {
|
||||||
|
setHasMore(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setEvents((oldEvents) => [...oldEvents, ...newEvents])
|
||||||
}
|
}
|
||||||
|
|
||||||
const observerInstance = new IntersectionObserver((entries) => {
|
const observerInstance = new IntersectionObserver((entries) => {
|
||||||
if (entries[0].isIntersecting && hasMore) {
|
if (entries[0].isIntersecting && hasMore) {
|
||||||
_loadMore()
|
loadMore()
|
||||||
}
|
}
|
||||||
}, options)
|
}, options)
|
||||||
|
|
||||||
@@ -86,39 +206,38 @@ const NoteList = forwardRef(
|
|||||||
observerInstance.unobserve(currentBottomRef)
|
observerInstance.unobserve(currentBottomRef)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [loading, hasMore, events, loadMore])
|
}, [loading, hasMore, events, showCount, timelineKey])
|
||||||
|
|
||||||
|
const showNewEvents = () => {
|
||||||
|
setEvents((oldEvents) => [...newEvents, ...oldEvents])
|
||||||
|
setNewEvents([])
|
||||||
|
setTimeout(() => {
|
||||||
|
scrollToTop()
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{newEvents.length > 0 && <NewNotesButton newEvents={newEvents} onClick={showNewEvents} />}
|
{filteredNewEvents.length > 0 && (
|
||||||
|
<NewNotesButton newEvents={filteredNewEvents} onClick={showNewEvents} />
|
||||||
|
)}
|
||||||
<div ref={topRef} className="scroll-mt-24" />
|
<div ref={topRef} className="scroll-mt-24" />
|
||||||
<PullToRefresh
|
<PullToRefresh
|
||||||
onRefresh={async () => {
|
onRefresh={async () => {
|
||||||
onRefresh?.()
|
setRefreshCount((count) => count + 1)
|
||||||
await new Promise((resolve) => setTimeout(resolve, 1000))
|
await new Promise((resolve) => setTimeout(resolve, 1000))
|
||||||
}}
|
}}
|
||||||
pullingContent=""
|
pullingContent=""
|
||||||
>
|
>
|
||||||
<div className="min-h-screen">
|
<div className="min-h-screen">
|
||||||
{events.slice(0, showCount).map((event) => {
|
{filteredEvents.map((event) => (
|
||||||
const id = isReplaceableEvent(event.kind)
|
<NoteCard
|
||||||
? getReplaceableCoordinateFromEvent(event)
|
key={event.id}
|
||||||
: event.id
|
className="w-full"
|
||||||
|
event={event}
|
||||||
if (idSet.has(id)) {
|
filterMutedNotes={filterMutedNotes}
|
||||||
return null
|
/>
|
||||||
}
|
))}
|
||||||
|
|
||||||
idSet.add(id)
|
|
||||||
return (
|
|
||||||
<NoteCard
|
|
||||||
key={event.id}
|
|
||||||
className="w-full"
|
|
||||||
event={event}
|
|
||||||
filterMutedNotes={filterMutedNotes}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
{hasMore || loading ? (
|
{hasMore || loading ? (
|
||||||
<div ref={bottomRef}>
|
<div ref={bottomRef}>
|
||||||
<NoteCardLoadingSkeleton />
|
<NoteCardLoadingSkeleton />
|
||||||
@@ -129,7 +248,7 @@ const NoteList = forwardRef(
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex justify-center w-full mt-2">
|
<div className="flex justify-center w-full mt-2">
|
||||||
<Button size="lg" onClick={onRefresh}>
|
<Button size="lg" onClick={() => setRefreshCount((count) => count + 1)}>
|
||||||
{t('reload notes')}
|
{t('reload notes')}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ import NormalFeed from '@/components/NormalFeed'
|
|||||||
import { useFeed } from '@/providers/FeedProvider'
|
import { useFeed } from '@/providers/FeedProvider'
|
||||||
import { useNostr } from '@/providers/NostrProvider'
|
import { useNostr } from '@/providers/NostrProvider'
|
||||||
import client from '@/services/client.service'
|
import client from '@/services/client.service'
|
||||||
import { TNormalFeedSubRequest } from '@/types'
|
import { TFeedSubRequest } from '@/types'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
export default function FollowingFeed() {
|
export default function FollowingFeed() {
|
||||||
const { pubkey } = useNostr()
|
const { pubkey } = useNostr()
|
||||||
const { feedInfo } = useFeed()
|
const { feedInfo } = useFeed()
|
||||||
const [subRequests, setSubRequests] = useState<TNormalFeedSubRequest[]>([])
|
const [subRequests, setSubRequests] = useState<TFeedSubRequest[]>([])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function init() {
|
async function init() {
|
||||||
@@ -24,5 +24,5 @@ export default function FollowingFeed() {
|
|||||||
init()
|
init()
|
||||||
}, [feedInfo.feedType, pubkey])
|
}, [feedInfo.feedType, pubkey])
|
||||||
|
|
||||||
return <NormalFeed subRequests={subRequests} />
|
return <NormalFeed subRequests={subRequests} isMainFeed />
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ export default function RelaysFeed() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NormalFeed subRequests={[{ urls: relayUrls, filter: {} }]} areAlgoRelays={areAlgoRelays} />
|
<NormalFeed
|
||||||
|
subRequests={[{ urls: relayUrls, filter: {} }]}
|
||||||
|
areAlgoRelays={areAlgoRelays}
|
||||||
|
isMainFeed
|
||||||
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { fetchPubkeysFromDomain, getWellKnownNip05Url } from '@/lib/nip05'
|
|||||||
import { useSecondaryPage } from '@/PageManager'
|
import { useSecondaryPage } from '@/PageManager'
|
||||||
import { useNostr } from '@/providers/NostrProvider'
|
import { useNostr } from '@/providers/NostrProvider'
|
||||||
import client from '@/services/client.service'
|
import client from '@/services/client.service'
|
||||||
import { TNormalFeedSubRequest } from '@/types'
|
import { TFeedSubRequest } from '@/types'
|
||||||
import { UserRound } from 'lucide-react'
|
import { UserRound } from 'lucide-react'
|
||||||
import React, { forwardRef, useEffect, useState } from 'react'
|
import React, { forwardRef, useEffect, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@@ -29,7 +29,7 @@ const NoteListPage = forwardRef(({ index }: { index?: number }, ref) => {
|
|||||||
}
|
}
|
||||||
| null
|
| null
|
||||||
>(null)
|
>(null)
|
||||||
const [subRequests, setSubRequests] = useState<TNormalFeedSubRequest[]>([])
|
const [subRequests, setSubRequests] = useState<TFeedSubRequest[]>([])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
@@ -94,6 +94,8 @@ const NoteListPage = forwardRef(({ index }: { index?: number }, ref) => {
|
|||||||
{pubkeys.length.toLocaleString()} <UserRound />
|
{pubkeys.length.toLocaleString()} <UserRound />
|
||||||
</Button>
|
</Button>
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
setSubRequests([])
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -102,7 +104,7 @@ const NoteListPage = forwardRef(({ index }: { index?: number }, ref) => {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
let content: React.ReactNode = null
|
let content: React.ReactNode = null
|
||||||
if (data?.type === 'domain' && setSubRequests.length === 0) {
|
if (data?.type === 'domain' && subRequests.length === 0) {
|
||||||
content = (
|
content = (
|
||||||
<div className="text-center w-full py-10">
|
<div className="text-center w-full py-10">
|
||||||
<span className="text-muted-foreground">
|
<span className="text-muted-foreground">
|
||||||
|
|||||||
99
src/pages/secondary/ProfilePage/ProfileFeed.tsx
Normal file
99
src/pages/secondary/ProfilePage/ProfileFeed.tsx
Normal 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'} />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
import Collapsible from '@/components/Collapsible'
|
import Collapsible from '@/components/Collapsible'
|
||||||
import FollowButton from '@/components/FollowButton'
|
import FollowButton from '@/components/FollowButton'
|
||||||
import Nip05 from '@/components/Nip05'
|
import Nip05 from '@/components/Nip05'
|
||||||
import Feed from '@/components/Feed'
|
import NpubQrCode from '@/components/NpubQrCode'
|
||||||
import ProfileAbout from '@/components/ProfileAbout'
|
import ProfileAbout from '@/components/ProfileAbout'
|
||||||
import ProfileBanner from '@/components/ProfileBanner'
|
import ProfileBanner from '@/components/ProfileBanner'
|
||||||
import ProfileOptions from '@/components/ProfileOptions'
|
import ProfileOptions from '@/components/ProfileOptions'
|
||||||
import ProfileZapButton from '@/components/ProfileZapButton'
|
import ProfileZapButton from '@/components/ProfileZapButton'
|
||||||
import PubkeyCopy from '@/components/PubkeyCopy'
|
import PubkeyCopy from '@/components/PubkeyCopy'
|
||||||
import NpubQrCode from '@/components/NpubQrCode'
|
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
|
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Skeleton } from '@/components/ui/skeleton'
|
import { Skeleton } from '@/components/ui/skeleton'
|
||||||
@@ -25,6 +24,7 @@ import { useTranslation } from 'react-i18next'
|
|||||||
import NotFoundPage from '../NotFoundPage'
|
import NotFoundPage from '../NotFoundPage'
|
||||||
import FollowedBy from './FollowedBy'
|
import FollowedBy from './FollowedBy'
|
||||||
import Followings from './Followings'
|
import Followings from './Followings'
|
||||||
|
import ProfileFeed from './ProfileFeed'
|
||||||
import Relays from './Relays'
|
import Relays from './Relays'
|
||||||
|
|
||||||
const ProfilePage = forwardRef(({ id, index }: { id?: string; index?: number }, ref) => {
|
const ProfilePage = forwardRef(({ id, index }: { id?: string; index?: number }, ref) => {
|
||||||
@@ -193,13 +193,7 @@ const ProfilePage = forwardRef(({ id, index }: { id?: string; index?: number },
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Feed
|
<ProfileFeed pubkey={pubkey} topSpace={topContainerHeight + 100} />
|
||||||
author={pubkey}
|
|
||||||
className="mt-2"
|
|
||||||
filterMutedNotes={false}
|
|
||||||
topSpace={topContainerHeight + 100}
|
|
||||||
skipTrustCheck
|
|
||||||
/>
|
|
||||||
</SecondaryPageLayout>
|
</SecondaryPageLayout>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { getProfileFromEvent, getRelayListFromEvent } from '@/lib/event-metadata
|
|||||||
import { formatPubkey, pubkeyToNpub, userIdToPubkey } from '@/lib/pubkey'
|
import { formatPubkey, pubkeyToNpub, userIdToPubkey } from '@/lib/pubkey'
|
||||||
import { getPubkeysFromPTags, getServersFromServerTags } from '@/lib/tag'
|
import { getPubkeysFromPTags, getServersFromServerTags } from '@/lib/tag'
|
||||||
import { isLocalNetworkUrl, isWebsocketUrl, normalizeUrl } from '@/lib/url'
|
import { isLocalNetworkUrl, isWebsocketUrl, normalizeUrl } from '@/lib/url'
|
||||||
import { ISigner, TProfile, TRelayList } from '@/types'
|
import { ISigner, TProfile, TRelayList, TSubRequestFilter } from '@/types'
|
||||||
import { sha256 } from '@noble/hashes/sha2'
|
import { sha256 } from '@noble/hashes/sha2'
|
||||||
import DataLoader from 'dataloader'
|
import DataLoader from 'dataloader'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
@@ -43,7 +43,7 @@ class ClientService extends EventTarget {
|
|||||||
string,
|
string,
|
||||||
| {
|
| {
|
||||||
refs: TTimelineRef[]
|
refs: TTimelineRef[]
|
||||||
filter: Omit<Filter, 'since' | 'until'> & { limit: number }
|
filter: TSubRequestFilter
|
||||||
urls: string[]
|
urls: string[]
|
||||||
}
|
}
|
||||||
| string[]
|
| string[]
|
||||||
@@ -178,7 +178,7 @@ class ClientService extends EventTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async subscribeTimeline(
|
async subscribeTimeline(
|
||||||
subRequests: { urls: string[]; filter: Omit<Filter, 'since' | 'until'> & { limit: number } }[],
|
subRequests: { urls: string[]; filter: TSubRequestFilter }[],
|
||||||
{
|
{
|
||||||
onEvents,
|
onEvents,
|
||||||
onNew
|
onNew
|
||||||
@@ -407,7 +407,7 @@ class ClientService extends EventTarget {
|
|||||||
|
|
||||||
private async _subscribeTimeline(
|
private async _subscribeTimeline(
|
||||||
urls: string[],
|
urls: string[],
|
||||||
filter: Omit<Filter, 'since' | 'until'> & { limit: number }, // filter with limit,
|
filter: TSubRequestFilter, // filter with limit,
|
||||||
{
|
{
|
||||||
onEvents,
|
onEvents,
|
||||||
onNew
|
onNew
|
||||||
|
|||||||
7
src/types/index.d.ts
vendored
7
src/types/index.d.ts
vendored
@@ -1,12 +1,9 @@
|
|||||||
import { Event, VerifiedEvent, Filter } from 'nostr-tools'
|
import { Event, VerifiedEvent, Filter } from 'nostr-tools'
|
||||||
import { POLL_TYPE } from './constants'
|
import { POLL_TYPE } from './constants'
|
||||||
|
|
||||||
export type TSubRequest = {
|
export type TSubRequestFilter = Omit<Filter, 'since' | 'until'> & { limit: number }
|
||||||
urls: string[]
|
|
||||||
filter: Omit<Filter, 'since' | 'until'> & { limit: number }
|
|
||||||
}
|
|
||||||
|
|
||||||
export type TNormalFeedSubRequest = {
|
export type TFeedSubRequest = {
|
||||||
urls: string[]
|
urls: string[]
|
||||||
filter: Omit<Filter, 'since' | 'until' | 'kinds'>
|
filter: Omit<Filter, 'since' | 'until' | 'kinds'>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user