feat: 24h pulse

This commit is contained in:
codytseng
2025-11-29 00:34:53 +08:00
parent b21855c294
commit ce7afeb250
31 changed files with 1086 additions and 123 deletions

View File

@@ -1,10 +1,12 @@
import NoteList, { TNoteListRef } from '@/components/NoteList'
import Tabs from '@/components/Tabs'
import UserAggregationList, { TUserAggregationListRef } from '@/components/UserAggregationList'
import { isTouchDevice } from '@/lib/utils'
import { useKindFilter } from '@/providers/KindFilterProvider'
import { useUserTrust } from '@/providers/UserTrustProvider'
import storage from '@/services/local-storage.service'
import { TFeedSubRequest, TNoteListMode } from '@/types'
import { Event } from 'nostr-tools'
import { useMemo, useRef, useState } from 'react'
import KindFilter from '../KindFilter'
import { RefreshButton } from '../RefreshButton'
@@ -13,12 +15,16 @@ export default function NormalFeed({
subRequests,
areAlgoRelays = false,
isMainFeed = false,
showRelayCloseReason = false
showRelayCloseReason = false,
filterFn,
disable24hMode = false
}: {
subRequests: TFeedSubRequest[]
areAlgoRelays?: boolean
isMainFeed?: boolean
showRelayCloseReason?: boolean
filterFn?: (event: Event) => boolean
disable24hMode?: boolean
}) {
const { hideUntrustedNotes } = useUserTrust()
const { showKinds } = useKindFilter()
@@ -26,13 +32,18 @@ export default function NormalFeed({
const [listMode, setListMode] = useState<TNoteListMode>(() => storage.getNoteListMode())
const supportTouch = useMemo(() => isTouchDevice(), [])
const noteListRef = useRef<TNoteListRef>(null)
const userAggregationListRef = useRef<TUserAggregationListRef>(null)
const topRef = useRef<HTMLDivElement>(null)
const showKindsFilter = useMemo(() => {
return subRequests.every((req) => !req.filter.kinds?.length)
}, [subRequests])
const handleListModeChange = (mode: TNoteListMode) => {
setListMode(mode)
if (isMainFeed) {
storage.setNoteListMode(mode)
}
noteListRef.current?.scrollToTop('smooth')
topRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' })
}
const handleShowKindsChange = (newShowKinds: number[]) => {
@@ -43,30 +54,56 @@ export default function NormalFeed({
return (
<>
<Tabs
value={listMode}
value={listMode === '24h' && disable24hMode ? 'posts' : listMode}
tabs={[
{ value: 'posts', label: 'Notes' },
{ value: 'postsAndReplies', label: 'Replies' }
{ value: 'postsAndReplies', label: 'Replies' },
...(!disable24hMode ? [{ value: '24h', label: '24h Pulse' }] : [])
]}
onTabChange={(listMode) => {
handleListModeChange(listMode as TNoteListMode)
}}
options={
<>
{!supportTouch && <RefreshButton onClick={() => noteListRef.current?.refresh()} />}
<KindFilter showKinds={temporaryShowKinds} onShowKindsChange={handleShowKindsChange} />
{!supportTouch && (
<RefreshButton
onClick={() => {
if (listMode === '24h') {
userAggregationListRef.current?.refresh()
} else {
noteListRef.current?.refresh()
}
}}
/>
)}
{showKindsFilter && (
<KindFilter
showKinds={temporaryShowKinds}
onShowKindsChange={handleShowKindsChange}
/>
)}
</>
}
/>
<NoteList
ref={noteListRef}
showKinds={temporaryShowKinds}
subRequests={subRequests}
hideReplies={listMode === 'posts'}
hideUntrustedNotes={hideUntrustedNotes}
areAlgoRelays={areAlgoRelays}
showRelayCloseReason={showRelayCloseReason}
/>
<div ref={topRef} className="scroll-mt-[calc(6rem+1px)]" />
{listMode === '24h' && !disable24hMode ? (
<UserAggregationList
ref={userAggregationListRef}
showKinds={temporaryShowKinds}
subRequests={subRequests}
filterFn={filterFn}
/>
) : (
<NoteList
ref={noteListRef}
showKinds={temporaryShowKinds}
subRequests={subRequests}
hideReplies={listMode === 'posts'}
hideUntrustedNotes={hideUntrustedNotes}
areAlgoRelays={areAlgoRelays}
showRelayCloseReason={showRelayCloseReason}
/>
)}
</>
)
}