import { useSecondaryPage } from '@/PageManager' import { useNoteStatsById } from '@/hooks/useNoteStatsById' import { formatAmount } from '@/lib/lightning' import { toProfile } from '@/lib/link' import { useScreenSize } from '@/providers/ScreenSizeProvider' import { Zap } from 'lucide-react' import { Event } from 'nostr-tools' import { useEffect, useMemo, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import Content from '../Content' import { FormattedTimestamp } from '../FormattedTimestamp' import Nip05 from '../Nip05' import UserAvatar from '../UserAvatar' import Username from '../Username' const SHOW_COUNT = 20 export default function ZapList({ event }: { event: Event }) { const { t } = useTranslation() const { push } = useSecondaryPage() const { isSmallScreen } = useScreenSize() const noteStats = useNoteStatsById(event.id) const filteredZaps = useMemo(() => { return (noteStats?.zaps ?? []).sort((a, b) => b.amount - a.amount) }, [noteStats, event.id]) const [showCount, setShowCount] = useState(SHOW_COUNT) const bottomRef = useRef(null) useEffect(() => { if (!bottomRef.current || filteredZaps.length <= showCount) return const obs = new IntersectionObserver( ([entry]) => { if (entry.isIntersecting) setShowCount((c) => c + SHOW_COUNT) }, { rootMargin: '10px', threshold: 0.1 } ) obs.observe(bottomRef.current) return () => obs.disconnect() }, [filteredZaps.length, showCount]) return (
{filteredZaps.slice(0, showCount).map((zap) => (
push(toProfile(zap.pubkey))} >
{formatAmount(zap.amount)}
))}
{filteredZaps.length > 0 ? t('No more zaps') : t('No zaps yet')}
) }