feat: 💨
This commit is contained in:
@@ -16,6 +16,7 @@ import client from '@/services/client.service'
|
|||||||
import { TFeedSubRequest } from '@/types'
|
import { TFeedSubRequest } from '@/types'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { Event } from 'nostr-tools'
|
import { Event } from 'nostr-tools'
|
||||||
|
import { decode } from 'nostr-tools/nip19'
|
||||||
import {
|
import {
|
||||||
forwardRef,
|
forwardRef,
|
||||||
useCallback,
|
useCallback,
|
||||||
@@ -29,6 +30,7 @@ import { useTranslation } from 'react-i18next'
|
|||||||
import PullToRefresh from 'react-simple-pull-to-refresh'
|
import PullToRefresh from 'react-simple-pull-to-refresh'
|
||||||
import { toast } from 'sonner'
|
import { toast } from 'sonner'
|
||||||
import NoteCard, { NoteCardLoadingSkeleton } from '../NoteCard'
|
import NoteCard, { NoteCardLoadingSkeleton } from '../NoteCard'
|
||||||
|
import PinnedNoteCard from '../PinnedNoteCard'
|
||||||
|
|
||||||
const LIMIT = 200
|
const LIMIT = 200
|
||||||
const ALGO_LIMIT = 500
|
const ALGO_LIMIT = 500
|
||||||
@@ -44,7 +46,7 @@ const NoteList = forwardRef(
|
|||||||
hideUntrustedNotes = false,
|
hideUntrustedNotes = false,
|
||||||
areAlgoRelays = false,
|
areAlgoRelays = false,
|
||||||
showRelayCloseReason = false,
|
showRelayCloseReason = false,
|
||||||
filteredEventHexIdSet = new Set<string>()
|
pinnedEventIds = []
|
||||||
}: {
|
}: {
|
||||||
subRequests: TFeedSubRequest[]
|
subRequests: TFeedSubRequest[]
|
||||||
showKinds: number[]
|
showKinds: number[]
|
||||||
@@ -53,7 +55,7 @@ const NoteList = forwardRef(
|
|||||||
hideUntrustedNotes?: boolean
|
hideUntrustedNotes?: boolean
|
||||||
areAlgoRelays?: boolean
|
areAlgoRelays?: boolean
|
||||||
showRelayCloseReason?: boolean
|
showRelayCloseReason?: boolean
|
||||||
filteredEventHexIdSet?: Set<string>
|
pinnedEventIds?: string[]
|
||||||
},
|
},
|
||||||
ref
|
ref
|
||||||
) => {
|
) => {
|
||||||
@@ -76,7 +78,19 @@ const NoteList = forwardRef(
|
|||||||
|
|
||||||
const shouldHideEvent = useCallback(
|
const shouldHideEvent = useCallback(
|
||||||
(evt: Event) => {
|
(evt: Event) => {
|
||||||
if (filteredEventHexIdSet.has(evt.id)) return true
|
const pinnedEventHexIdSet = new Set()
|
||||||
|
pinnedEventIds.forEach((id) => {
|
||||||
|
try {
|
||||||
|
const { type, data } = decode(id)
|
||||||
|
if (type === 'nevent') {
|
||||||
|
pinnedEventHexIdSet.add(data.id)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (pinnedEventHexIdSet.has(evt.id)) return true
|
||||||
if (isEventDeleted(evt)) return true
|
if (isEventDeleted(evt)) return true
|
||||||
if (hideReplies && isReplyNoteEvent(evt)) return true
|
if (hideReplies && isReplyNoteEvent(evt)) return true
|
||||||
if (hideUntrustedNotes && !isUserTrusted(evt.pubkey)) return true
|
if (hideUntrustedNotes && !isUserTrusted(evt.pubkey)) return true
|
||||||
@@ -91,7 +105,7 @@ const NoteList = forwardRef(
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
[hideReplies, hideUntrustedNotes, mutePubkeySet, filteredEventHexIdSet, isEventDeleted]
|
[hideReplies, hideUntrustedNotes, mutePubkeySet, pinnedEventIds, isEventDeleted]
|
||||||
)
|
)
|
||||||
|
|
||||||
const filteredEvents = useMemo(() => {
|
const filteredEvents = useMemo(() => {
|
||||||
@@ -284,6 +298,9 @@ const NoteList = forwardRef(
|
|||||||
|
|
||||||
const list = (
|
const list = (
|
||||||
<div className="min-h-screen">
|
<div className="min-h-screen">
|
||||||
|
{pinnedEventIds.map((id) => (
|
||||||
|
<PinnedNoteCard key={id} eventId={id} className="w-full" />
|
||||||
|
))}
|
||||||
{filteredEvents.map((event) => (
|
{filteredEvents.map((event) => (
|
||||||
<NoteCard
|
<NoteCard
|
||||||
key={event.id}
|
key={event.id}
|
||||||
|
|||||||
22
src/components/PinnedNoteCard/index.tsx
Normal file
22
src/components/PinnedNoteCard/index.tsx
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { useFetchEvent } from '@/hooks'
|
||||||
|
import NoteCard, { NoteCardLoadingSkeleton } from '../NoteCard'
|
||||||
|
|
||||||
|
export default function PinnedNoteCard({
|
||||||
|
eventId,
|
||||||
|
className
|
||||||
|
}: {
|
||||||
|
eventId: string
|
||||||
|
className?: string
|
||||||
|
}) {
|
||||||
|
const { event, isFetching } = useFetchEvent(eventId)
|
||||||
|
|
||||||
|
if (isFetching) {
|
||||||
|
return <NoteCardLoadingSkeleton />
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!event) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return <NoteCard event={event} className={className} pinned />
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@ import KindFilter from '@/components/KindFilter'
|
|||||||
import NoteList, { TNoteListRef } from '@/components/NoteList'
|
import NoteList, { TNoteListRef } from '@/components/NoteList'
|
||||||
import Tabs from '@/components/Tabs'
|
import Tabs from '@/components/Tabs'
|
||||||
import { BIG_RELAY_URLS, MAX_PINNED_NOTES } from '@/constants'
|
import { BIG_RELAY_URLS, MAX_PINNED_NOTES } from '@/constants'
|
||||||
import { useFetchEvent } from '@/hooks'
|
|
||||||
import { generateBech32IdFromETag } from '@/lib/tag'
|
import { generateBech32IdFromETag } from '@/lib/tag'
|
||||||
import { isTouchDevice } from '@/lib/utils'
|
import { isTouchDevice } from '@/lib/utils'
|
||||||
import { useKindFilter } from '@/providers/KindFilterProvider'
|
import { useKindFilter } from '@/providers/KindFilterProvider'
|
||||||
@@ -12,7 +11,6 @@ import storage from '@/services/local-storage.service'
|
|||||||
import { TFeedSubRequest, TNoteListMode } from '@/types'
|
import { TFeedSubRequest, TNoteListMode } from '@/types'
|
||||||
import { NostrEvent } from 'nostr-tools'
|
import { NostrEvent } from 'nostr-tools'
|
||||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||||
import NoteCard, { NoteCardLoadingSkeleton } from '../NoteCard'
|
|
||||||
import { RefreshButton } from '../RefreshButton'
|
import { RefreshButton } from '../RefreshButton'
|
||||||
|
|
||||||
export default function ProfileFeed({
|
export default function ProfileFeed({
|
||||||
@@ -28,7 +26,6 @@ export default function ProfileFeed({
|
|||||||
const [listMode, setListMode] = useState<TNoteListMode>(() => storage.getNoteListMode())
|
const [listMode, setListMode] = useState<TNoteListMode>(() => storage.getNoteListMode())
|
||||||
const [subRequests, setSubRequests] = useState<TFeedSubRequest[]>([])
|
const [subRequests, setSubRequests] = useState<TFeedSubRequest[]>([])
|
||||||
const [pinnedEventIds, setPinnedEventIds] = useState<string[]>([])
|
const [pinnedEventIds, setPinnedEventIds] = useState<string[]>([])
|
||||||
const [pinnedEventHexIdSet, setPinnedEventHexIdSet] = useState<Set<string>>(new Set())
|
|
||||||
const tabs = useMemo(() => {
|
const tabs = useMemo(() => {
|
||||||
const _tabs = [
|
const _tabs = [
|
||||||
{ value: 'posts', label: 'Notes' },
|
{ value: 'posts', label: 'Notes' },
|
||||||
@@ -43,7 +40,6 @@ export default function ProfileFeed({
|
|||||||
}, [myPubkey, pubkey])
|
}, [myPubkey, pubkey])
|
||||||
const supportTouch = useMemo(() => isTouchDevice(), [])
|
const supportTouch = useMemo(() => isTouchDevice(), [])
|
||||||
const noteListRef = useRef<TNoteListRef>(null)
|
const noteListRef = useRef<TNoteListRef>(null)
|
||||||
const topRef = useRef<HTMLDivElement>(null)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const initPinnedEventIds = async () => {
|
const initPinnedEventIds = async () => {
|
||||||
@@ -73,7 +69,6 @@ export default function ProfileFeed({
|
|||||||
})
|
})
|
||||||
.filter(Boolean) as string[]) ?? []
|
.filter(Boolean) as string[]) ?? []
|
||||||
setPinnedEventIds(ids)
|
setPinnedEventIds(ids)
|
||||||
setPinnedEventHexIdSet(hexIdSet)
|
|
||||||
}
|
}
|
||||||
initPinnedEventIds()
|
initPinnedEventIds()
|
||||||
}, [pubkey, myPubkey, myPinListEvent])
|
}, [pubkey, myPubkey, myPinListEvent])
|
||||||
@@ -125,12 +120,12 @@ export default function ProfileFeed({
|
|||||||
|
|
||||||
const handleListModeChange = (mode: TNoteListMode) => {
|
const handleListModeChange = (mode: TNoteListMode) => {
|
||||||
setListMode(mode)
|
setListMode(mode)
|
||||||
topRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
noteListRef.current?.scrollToTop('smooth')
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleShowKindsChange = (newShowKinds: number[]) => {
|
const handleShowKindsChange = (newShowKinds: number[]) => {
|
||||||
setTemporaryShowKinds(newShowKinds)
|
setTemporaryShowKinds(newShowKinds)
|
||||||
topRef.current?.scrollIntoView({ behavior: 'instant', block: 'start' })
|
noteListRef.current?.scrollToTop('instant')
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -149,32 +144,14 @@ export default function ProfileFeed({
|
|||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<div ref={topRef} className="scroll-mt-[calc(6rem+1px)]" />
|
|
||||||
{pinnedEventIds.map((eventId) => (
|
|
||||||
<PinnedNote key={eventId} eventId={eventId} />
|
|
||||||
))}
|
|
||||||
<NoteList
|
<NoteList
|
||||||
ref={noteListRef}
|
ref={noteListRef}
|
||||||
subRequests={subRequests}
|
subRequests={subRequests}
|
||||||
showKinds={temporaryShowKinds}
|
showKinds={temporaryShowKinds}
|
||||||
hideReplies={listMode === 'posts'}
|
hideReplies={listMode === 'posts'}
|
||||||
filterMutedNotes={false}
|
filterMutedNotes={false}
|
||||||
filteredEventHexIdSet={pinnedEventHexIdSet}
|
pinnedEventIds={listMode === 'you' ? [] : pinnedEventIds}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function PinnedNote({ eventId }: { eventId: string }) {
|
|
||||||
const { event, isFetching } = useFetchEvent(eventId)
|
|
||||||
|
|
||||||
if (isFetching) {
|
|
||||||
return <NoteCardLoadingSkeleton />
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!event) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return <NoteCard event={event} className="w-full" pinned />
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user