import MuteButton from '@/components/MuteButton' import Nip05 from '@/components/Nip05' import { Button } from '@/components/ui/button' import UserAvatar from '@/components/UserAvatar' import Username from '@/components/Username' import { useFetchProfile } from '@/hooks' import SecondaryPageLayout from '@/layouts/SecondaryPageLayout' import { useMuteList } from '@/providers/MuteListProvider' import { useNostr } from '@/providers/NostrProvider' import { Loader, Lock, Unlock } from 'lucide-react' import { forwardRef, useEffect, useMemo, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import NotFoundPage from '../NotFoundPage' const MuteListPage = forwardRef(({ index }: { index?: number }, ref) => { const { t } = useTranslation() const { profile, pubkey } = useNostr() const { getMutePubkeys } = useMuteList() const mutePubkeys = useMemo(() => getMutePubkeys(), [pubkey]) const [visibleMutePubkeys, setVisibleMutePubkeys] = useState([]) const bottomRef = useRef(null) useEffect(() => { setVisibleMutePubkeys(mutePubkeys.slice(0, 10)) }, [mutePubkeys]) useEffect(() => { const options = { root: null, rootMargin: '10px', threshold: 1 } const observerInstance = new IntersectionObserver((entries) => { if (entries[0].isIntersecting && mutePubkeys.length > visibleMutePubkeys.length) { setVisibleMutePubkeys((prev) => [ ...prev, ...mutePubkeys.slice(prev.length, prev.length + 10) ]) } }, options) const currentBottomRef = bottomRef.current if (currentBottomRef) { observerInstance.observe(currentBottomRef) } return () => { if (observerInstance && currentBottomRef) { observerInstance.unobserve(currentBottomRef) } } }, [visibleMutePubkeys, mutePubkeys]) if (!profile) { return } return (
{visibleMutePubkeys.map((pubkey, index) => ( ))} {mutePubkeys.length > visibleMutePubkeys.length &&
}
) }) MuteListPage.displayName = 'MuteListPage' export default MuteListPage function UserItem({ pubkey }: { pubkey: string }) { const { changing, getMuteType, switchToPrivateMute, switchToPublicMute } = useMuteList() const { profile } = useFetchProfile(pubkey) const muteType = useMemo(() => getMuteType(pubkey), [pubkey, getMuteType]) const [switching, setSwitching] = useState(false) return (
{profile?.about}
{switching ? ( ) : muteType === 'private' ? ( ) : muteType === 'public' ? ( ) : null}
) }