import { useEffect, useMemo, useRef } from 'react'; import { useLocation, useParams } from 'react-router-dom'; import { useAccount, useFeed, useSubplebbit } from '@plebbit/plebbit-react-hooks'; import { Virtuoso, VirtuosoHandle, StateSnapshot } from 'react-virtuoso'; import { useTranslation } from 'react-i18next'; import styles from './board.module.css'; import { isAllView, isSubscriptionsView } from '../../lib/utils/view-utils'; import useBlockedCommentsStore from '../../stores/useBlockedCommentsStore'; import useBlockedComments from '../../hooks/use-blocked-comments'; import { useDefaultSubplebbitAddresses } from '../../hooks/use-default-subplebbits'; import useFeedStateString from '../../hooks/use-feed-state-string'; import useReplyModal from '../../hooks/use-reply-modal'; import LoadingEllipsis from '../../components/loading-ellipsis'; import Post from '../../components/post'; import ReplyModal from '../../components/reply-modal'; import SettingsModal from '../../components/settings-modal'; import SubplebbitDescription from '../../components/subplebbit-description'; import SubplebbitRules from '../../components/subplebbit-rules'; const lastVirtuosoStates: { [key: string]: StateSnapshot } = {}; const Board = () => { const { t } = useTranslation(); const location = useLocation(); const { subplebbitAddress } = useParams<{ subplebbitAddress: string }>(); const isInAllView = isAllView(location.pathname); const defaultSubplebbitAddresses = useDefaultSubplebbitAddresses(); const account = useAccount(); const subscriptions = account?.subscriptions; const isInSubscriptionsView = isSubscriptionsView(location.pathname); const subplebbitAddresses = useMemo(() => { if (isInAllView) { return defaultSubplebbitAddresses; } if (isInSubscriptionsView) { return subscriptions || []; } return [subplebbitAddress]; }, [isInAllView, isInSubscriptionsView, subplebbitAddress, defaultSubplebbitAddresses, subscriptions]); const sortType = 'active'; const { feed, hasMore, loadMore } = useFeed({ subplebbitAddresses, sortType }); const { resetShowBlockedComments, showBlockedComments, setShowBlockedComments } = useBlockedCommentsStore(); const blockedComments = useBlockedComments(subplebbitAddress); useEffect(() => { resetShowBlockedComments(); }, [subplebbitAddress, resetShowBlockedComments]); useEffect(() => { if (blockedComments.length === 0) { setShowBlockedComments(false); } }, [blockedComments, setShowBlockedComments]); const subplebbit = useSubplebbit({ subplebbitAddress }); const { createdAt, description, rules, shortAddress, state, suggested } = subplebbit || {}; const title = isInAllView ? t('all') : isInSubscriptionsView ? t('subscriptions') : subplebbit?.title; const { activeCid, closeModal, openReplyModal, showReplyModal, scrollY } = useReplyModal(); const loadingStateString = useFeedStateString(subplebbitAddresses) || t('loading'); const loadingString = (