import { useSecondaryPage } from '@/PageManager' import { useStuffStatsById } from '@/hooks/useStuffStatsById' import { toProfile } from '@/lib/link' import { useScreenSize } from '@/providers/ScreenSizeProvider' import { useUserTrust } from '@/providers/UserTrustProvider' import { Repeat } from 'lucide-react' import { Event } from 'nostr-tools' import { useEffect, useMemo, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { FormattedTimestamp } from '../FormattedTimestamp' import Nip05 from '../Nip05' import UserAvatar from '../UserAvatar' import Username from '../Username' const SHOW_COUNT = 20 export default function RepostList({ event }: { event: Event }) { const { t } = useTranslation() const { push } = useSecondaryPage() const { isSmallScreen } = useScreenSize() const { hideUntrustedInteractions, isUserTrusted } = useUserTrust() const noteStats = useStuffStatsById(event.id) const filteredReposts = useMemo(() => { return (noteStats?.reposts ?? []) .filter((repost) => !hideUntrustedInteractions || isUserTrusted(repost.pubkey)) .sort((a, b) => b.created_at - a.created_at) }, [noteStats, event.id, hideUntrustedInteractions, isUserTrusted]) const [showCount, setShowCount] = useState(SHOW_COUNT) const bottomRef = useRef(null) useEffect(() => { if (!bottomRef.current || filteredReposts.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() }, [filteredReposts.length, showCount]) return (
{filteredReposts.slice(0, showCount).map((repost) => (
push(toProfile(repost.pubkey))} >
))}
{filteredReposts.length > 0 ? t('No more reposts') : t('No reposts yet')}
) }