refactor: optimize note interaction data processing

This commit is contained in:
codytseng 2025-07-03 21:46:12 +08:00
parent 2d2153448d
commit 18ce08ce07
13 changed files with 289 additions and 293 deletions

View file

@ -1,6 +1,6 @@
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area'
import { useNoteStatsById } from '@/hooks/useNoteStatsById'
import { formatAmount } from '@/lib/lightning'
import { useNoteStats } from '@/providers/NoteStatsProvider'
import { Zap } from 'lucide-react'
import { Event } from 'nostr-tools'
import { useMemo, useState } from 'react'
@ -8,12 +8,11 @@ import { SimpleUserAvatar } from '../UserAvatar'
import ZapDialog from '../ZapDialog'
export default function TopZaps({ event }: { event: Event }) {
const { noteStatsMap } = useNoteStats()
const noteStats = useNoteStatsById(event.id)
const [zapIndex, setZapIndex] = useState(-1)
const topZaps = useMemo(() => {
const stats = noteStatsMap.get(event.id) || {}
return stats.zaps?.slice(0, 10) || []
}, [noteStatsMap, event])
return noteStats?.zaps?.sort((a, b) => b.amount - a.amount).slice(0, 10) || []
}, [noteStats])
if (!topZaps.length) return null