mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat: add "hidden threads" counter and button in catalog and board view, store and hook
This commit is contained in:
@@ -17,6 +17,15 @@
|
|||||||
padding-bottom: 20px;
|
padding-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.showBlockedButton {
|
||||||
|
color: var(--button-desktop-text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.showBlockedButton:hover {
|
||||||
|
color: var(--button-desktop-text-color-hover);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 640px) {
|
@media (max-width: 640px) {
|
||||||
.desktopBoardButtons {
|
.desktopBoardButtons {
|
||||||
display: none;
|
display: none;
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ import { Link, useLocation, useParams } from 'react-router-dom';
|
|||||||
import { useAccountComment, useSubscribe } from '@plebbit/plebbit-react-hooks';
|
import { useAccountComment, useSubscribe } from '@plebbit/plebbit-react-hooks';
|
||||||
import styles from './board-buttons.module.css';
|
import styles from './board-buttons.module.css';
|
||||||
import { isAllView, isCatalogView, isPendingPostView, isPostPageView, isSubscriptionsView } from '../../lib/utils/view-utils';
|
import { isAllView, isCatalogView, isPendingPostView, isPostPageView, isSubscriptionsView } from '../../lib/utils/view-utils';
|
||||||
|
import useBlockedComments from '../../hooks/use-blocked-comments';
|
||||||
|
import useBlockedCommentsStore from '../../stores/useBlockedCommentsStore';
|
||||||
|
|
||||||
interface BoardButtonsProps {
|
interface BoardButtonsProps {
|
||||||
isInAllView?: boolean;
|
isInAllView?: boolean;
|
||||||
address: string | undefined;
|
address?: string | undefined;
|
||||||
isInCatalogView?: boolean;
|
isInCatalogView?: boolean;
|
||||||
isInSubscriptionsView?: boolean;
|
isInSubscriptionsView?: boolean;
|
||||||
}
|
}
|
||||||
@@ -105,6 +107,9 @@ export const DesktopBoardButtons = () => {
|
|||||||
const isInPostView = isPostPageView(location.pathname, params);
|
const isInPostView = isPostPageView(location.pathname, params);
|
||||||
const isInSubscriptionsView = isSubscriptionsView(location.pathname);
|
const isInSubscriptionsView = isSubscriptionsView(location.pathname);
|
||||||
|
|
||||||
|
const { showBlockedComments, setShowBlockedComments } = useBlockedCommentsStore();
|
||||||
|
const blockedComments = useBlockedComments(params?.subplebbitAddress);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.desktopBoardButtons}>
|
<div className={styles.desktopBoardButtons}>
|
||||||
<hr />
|
<hr />
|
||||||
@@ -120,6 +125,16 @@ export const DesktopBoardButtons = () => {
|
|||||||
<>
|
<>
|
||||||
[<OptionsButton />] [
|
[<OptionsButton />] [
|
||||||
<CatalogButton address={subplebbitAddress} isInAllView={isInAllView} isInCatalogView={isInCatalogView} isInSubscriptionsView={isInSubscriptionsView} />]
|
<CatalogButton address={subplebbitAddress} isInAllView={isInAllView} isInCatalogView={isInCatalogView} isInSubscriptionsView={isInSubscriptionsView} />]
|
||||||
|
{blockedComments?.length > 0 && (
|
||||||
|
<span className={styles.blockedAddresses}>
|
||||||
|
{' '}
|
||||||
|
— Hidden threads: <strong>{blockedComments.length}</strong> [
|
||||||
|
<span className={styles.showBlockedButton} onClick={() => setShowBlockedComments(!showBlockedComments)}>
|
||||||
|
{showBlockedComments ? 'Back' : 'Show'}
|
||||||
|
</span>
|
||||||
|
]
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
{!(isInAllView || isInSubscriptionsView) && (
|
{!(isInAllView || isInSubscriptionsView) && (
|
||||||
<span className={styles.subscribeButton}>
|
<span className={styles.subscribeButton}>
|
||||||
[<SubscribeButton address={subplebbitAddress} />]
|
[<SubscribeButton address={subplebbitAddress} />]
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ interface MediaProps {
|
|||||||
linkWidth?: number;
|
linkWidth?: number;
|
||||||
showThumbnail?: boolean;
|
showThumbnail?: boolean;
|
||||||
setShowThumbnail: (showThumbnail: boolean) => void;
|
setShowThumbnail: (showThumbnail: boolean) => void;
|
||||||
toggleExpanded?: () => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Thumbnail = ({ commentMediaInfo, isOutOfFeed, isReply, linkHeight, linkWidth, setShowThumbnail }: MediaProps) => {
|
const Thumbnail = ({ commentMediaInfo, isOutOfFeed, isReply, linkHeight, linkWidth, setShowThumbnail }: MediaProps) => {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import PostMenuDesktop from './post-menu-desktop/';
|
|||||||
import { PostProps } from '../post';
|
import { PostProps } from '../post';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
const PostInfo = ({ openReplyModal, post, roles, isBlocked }: PostProps) => {
|
const PostInfo = ({ openReplyModal, post, roles, isHidden }: PostProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { author, cid, locked, pinned, parentCid, postCid, shortCid, state, subplebbitAddress, timestamp, title } = post || {};
|
const { author, cid, locked, pinned, parentCid, postCid, shortCid, state, subplebbitAddress, timestamp, title } = post || {};
|
||||||
const { address, displayName, shortAddress } = author || {};
|
const { address, displayName, shortAddress } = author || {};
|
||||||
@@ -44,7 +44,7 @@ const PostInfo = ({ openReplyModal, post, roles, isBlocked }: PostProps) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.postInfo}>
|
<div className={styles.postInfo}>
|
||||||
{!isBlocked && (
|
{!isHidden && (
|
||||||
<span className={styles.checkbox}>
|
<span className={styles.checkbox}>
|
||||||
<input type='checkbox' />
|
<input type='checkbox' />
|
||||||
</span>
|
</span>
|
||||||
@@ -92,7 +92,7 @@ const PostInfo = ({ openReplyModal, post, roles, isBlocked }: PostProps) => {
|
|||||||
<img src='/assets/icons/closed.gif' alt='' className={styles.closedIcon} title={t('closed')} />
|
<img src='/assets/icons/closed.gif' alt='' className={styles.closedIcon} title={t('closed')} />
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{!isInPostView && !isReply && !isBlocked && (
|
{!isInPostView && !isReply && !isHidden && (
|
||||||
<span className={styles.replyButton}>
|
<span className={styles.replyButton}>
|
||||||
[
|
[
|
||||||
<Link
|
<Link
|
||||||
@@ -216,13 +216,14 @@ const PostDesktop = ({ openReplyModal, post, roles, showAllReplies }: PostProps)
|
|||||||
const { cid, content, link, pinned, replyCount, subplebbitAddress } = post || {};
|
const { cid, content, link, pinned, replyCount, subplebbitAddress } = post || {};
|
||||||
const { isDescription, isRules } = post || {}; // custom properties, not from api
|
const { isDescription, isRules } = post || {}; // custom properties, not from api
|
||||||
|
|
||||||
const { blocked, unblock, block } = useBlock({ address: cid });
|
|
||||||
|
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const isInPendingPostView = isPendingPostView(location.pathname, params);
|
const isInPendingPostView = isPendingPostView(location.pathname, params);
|
||||||
const isInPostPageView = isPostPageView(location.pathname, params);
|
const isInPostPageView = isPostPageView(location.pathname, params);
|
||||||
|
|
||||||
|
const { blocked, unblock, block } = useBlock({ address: cid });
|
||||||
|
const isHidden = blocked && !isInPostPageView;
|
||||||
|
|
||||||
const replies = useReplies(post);
|
const replies = useReplies(post);
|
||||||
const visiblelinksCount = useCountLinksInReplies(post, 5);
|
const visiblelinksCount = useCountLinksInReplies(post, 5);
|
||||||
const totallinksCount = useCountLinksInReplies(post);
|
const totallinksCount = useCountLinksInReplies(post);
|
||||||
@@ -234,17 +235,17 @@ const PostDesktop = ({ openReplyModal, post, roles, showAllReplies }: PostProps)
|
|||||||
<div className={styles.hrWrapper}>
|
<div className={styles.hrWrapper}>
|
||||||
<hr />
|
<hr />
|
||||||
</div>
|
</div>
|
||||||
<div className={blocked ? styles.postDesktopBlocked : ''}>
|
<div className={isHidden ? styles.postDesktopBlocked : ''}>
|
||||||
{!isInPostPageView && !isDescription && !isRules && (
|
{!isInPostPageView && !isDescription && !isRules && (
|
||||||
<span className={styles.hideButtonWrapper}>
|
<span className={styles.hideButtonWrapper}>
|
||||||
<span className={`${styles.hideButton} ${blocked ? styles.unhideThread : styles.hideThread}`} onClick={blocked ? unblock : block} />
|
<span className={`${styles.hideButton} ${blocked ? styles.unhideThread : styles.hideThread}`} onClick={blocked ? unblock : block} />
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{link && !blocked && isValidURL(link) && <PostMedia post={post} />}
|
{link && !isHidden && isValidURL(link) && <PostMedia post={post} />}
|
||||||
<PostInfo isBlocked={blocked} openReplyModal={openReplyModal} post={post} roles={roles} />
|
<PostInfo isHidden={isHidden} openReplyModal={openReplyModal} post={post} roles={roles} />
|
||||||
{!blocked && !content && <div className={styles.spacer} />}
|
{!isHidden && !content && <div className={styles.spacer} />}
|
||||||
{!blocked && content && <PostMessage post={post} />}
|
{!isHidden && content && <PostMessage post={post} />}
|
||||||
{!blocked && !isDescription && !isRules && !isInPendingPostView && (replies.length > 5 || (pinned && replies.length > 0)) && !isInPostPageView && (
|
{!isHidden && !isDescription && !isRules && !isInPendingPostView && (replies.length > 5 || (pinned && replies.length > 0)) && !isInPostPageView && (
|
||||||
<span className={styles.summary}>
|
<span className={styles.summary}>
|
||||||
<span className={styles.expandButtonWrapper}>
|
<span className={styles.expandButtonWrapper}>
|
||||||
<span className={styles.expandButton} />
|
<span className={styles.expandButton} />
|
||||||
@@ -261,7 +262,7 @@ const PostDesktop = ({ openReplyModal, post, roles, showAllReplies }: PostProps)
|
|||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{!blocked &&
|
{!isHidden &&
|
||||||
!(pinned && !isInPostPageView) &&
|
!(pinned && !isInPostPageView) &&
|
||||||
!isInPendingPostView &&
|
!isInPendingPostView &&
|
||||||
!isDescription &&
|
!isDescription &&
|
||||||
|
|||||||
@@ -141,7 +141,13 @@ const PostMenuDesktop = ({ post }: { post: Comment }) => {
|
|||||||
<div className={styles.postMenu} ref={refs.setFloating} style={floatingStyles} aria-labelledby={headingId} {...getFloatingProps()}>
|
<div className={styles.postMenu} ref={refs.setFloating} style={floatingStyles} aria-labelledby={headingId} {...getFloatingProps()}>
|
||||||
{cid && subplebbitAddress && <CopyLinkButton cid={cid} subplebbitAddress={subplebbitAddress} onClose={handleClose} />}
|
{cid && subplebbitAddress && <CopyLinkButton cid={cid} subplebbitAddress={subplebbitAddress} onClose={handleClose} />}
|
||||||
{!isInPostPageView && !isDescription && !isRules && (
|
{!isInPostPageView && !isDescription && !isRules && (
|
||||||
<div className={styles.postMenuItem} onClick={blocked ? unblock : block}>
|
<div
|
||||||
|
className={styles.postMenuItem}
|
||||||
|
onClick={() => {
|
||||||
|
blocked ? unblock() : block();
|
||||||
|
handleClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
{blocked ? 'Unhide' : 'Hide'} {postCid === cid ? 'thread' : 'post'}
|
{blocked ? 'Unhide' : 'Hide'} {postCid === cid ? 'thread' : 'post'}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import PostMobile from './post-mobile';
|
|||||||
|
|
||||||
export interface PostProps {
|
export interface PostProps {
|
||||||
index?: number;
|
index?: number;
|
||||||
isBlocked?: boolean;
|
isHidden?: boolean;
|
||||||
post?: any;
|
post?: any;
|
||||||
reply?: any;
|
reply?: any;
|
||||||
roles?: Role[];
|
roles?: Role[];
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { useMemo } from 'react';
|
||||||
|
import { Comment, useAccount, useComments } from '@plebbit/plebbit-react-hooks';
|
||||||
|
|
||||||
|
const useBlockedComments = (subplebbitAddress?: string): Comment[] => {
|
||||||
|
const account = useAccount();
|
||||||
|
|
||||||
|
const commentCids = useMemo(() => {
|
||||||
|
return Object.entries(account.blockedAddresses)
|
||||||
|
.filter(([address, isBlocked]) => {
|
||||||
|
const isValidCommentCid = !address || /^Qm[a-zA-Z0-9]{44}$/.test(address);
|
||||||
|
return isBlocked && isValidCommentCid;
|
||||||
|
})
|
||||||
|
.map(([address]) => address);
|
||||||
|
}, [account]);
|
||||||
|
|
||||||
|
const { comments } = useComments({ commentCids });
|
||||||
|
|
||||||
|
const filteredComments = useMemo(() => {
|
||||||
|
const validComments = comments.filter((comment): comment is Comment => comment !== undefined);
|
||||||
|
|
||||||
|
if (!subplebbitAddress) {
|
||||||
|
return validComments;
|
||||||
|
}
|
||||||
|
|
||||||
|
return validComments.filter((comment: Comment) => comment.subplebbitAddress === subplebbitAddress);
|
||||||
|
}, [comments, subplebbitAddress]);
|
||||||
|
|
||||||
|
return filteredComments;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useBlockedComments;
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { create } from 'zustand';
|
||||||
|
|
||||||
|
interface StoreState {
|
||||||
|
showBlockedComments: boolean;
|
||||||
|
setShowBlockedComments: (show: boolean) => void;
|
||||||
|
resetShowBlockedComments: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const useStore = create<StoreState>((set) => ({
|
||||||
|
showBlockedComments: false,
|
||||||
|
setShowBlockedComments: (show) => set({ showBlockedComments: show }),
|
||||||
|
resetShowBlockedComments: () => set({ showBlockedComments: false }),
|
||||||
|
}));
|
||||||
|
|
||||||
|
export default useStore;
|
||||||
+36
-17
@@ -5,6 +5,8 @@ import { Virtuoso, VirtuosoHandle, StateSnapshot } from 'react-virtuoso';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import styles from './board.module.css';
|
import styles from './board.module.css';
|
||||||
import { isAllView, isSubscriptionsView } from '../../lib/utils/view-utils';
|
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 { useDefaultSubplebbitAddresses } from '../../hooks/use-default-subplebbits';
|
||||||
import useFeedStateString from '../../hooks/use-feed-state-string';
|
import useFeedStateString from '../../hooks/use-feed-state-string';
|
||||||
import useReplyModal from '../../hooks/use-reply-modal';
|
import useReplyModal from '../../hooks/use-reply-modal';
|
||||||
@@ -42,6 +44,19 @@ const Board = () => {
|
|||||||
const sortType = 'active';
|
const sortType = 'active';
|
||||||
const { feed, hasMore, loadMore } = useFeed({ subplebbitAddresses, sortType });
|
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 subplebbit = useSubplebbit({ subplebbitAddress });
|
||||||
const { createdAt, description, rules, shortAddress, state, suggested } = subplebbit || {};
|
const { createdAt, description, rules, shortAddress, state, suggested } = subplebbit || {};
|
||||||
const title = isInAllView ? t('all') : isInSubscriptionsView ? t('subscriptions') : subplebbit?.title;
|
const title = isInAllView ? t('all') : isInSubscriptionsView ? t('subscriptions') : subplebbit?.title;
|
||||||
@@ -96,7 +111,7 @@ const Board = () => {
|
|||||||
<div className={styles.content}>
|
<div className={styles.content}>
|
||||||
{location.pathname.endsWith('/settings') && <SettingsModal />}
|
{location.pathname.endsWith('/settings') && <SettingsModal />}
|
||||||
{showReplyModal && activeCid && <ReplyModal closeModal={closeModal} parentCid={activeCid} scrollY={scrollY} />}
|
{showReplyModal && activeCid && <ReplyModal closeModal={closeModal} parentCid={activeCid} scrollY={scrollY} />}
|
||||||
{feed.length > 0 && (
|
{feed.length > 0 && !showBlockedComments && (
|
||||||
<>
|
<>
|
||||||
{rules && rules.length > 0 && <SubplebbitRules subplebbitAddress={subplebbitAddress} createdAt={createdAt} rules={rules} />}
|
{rules && rules.length > 0 && <SubplebbitRules subplebbitAddress={subplebbitAddress} createdAt={createdAt} rules={rules} />}
|
||||||
{((description && description.length > 0) || isInAllView) && (
|
{((description && description.length > 0) || isInAllView) && (
|
||||||
@@ -111,23 +126,27 @@ const Board = () => {
|
|||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<Virtuoso
|
{showBlockedComments ? (
|
||||||
increaseViewportBy={{ bottom: 1200, top: 1200 }}
|
blockedComments.map((comment) => <Post key={comment.cid} post={comment} />)
|
||||||
totalCount={feed?.length || 0}
|
) : (
|
||||||
data={feed}
|
<Virtuoso
|
||||||
itemContent={(index, post) => {
|
increaseViewportBy={{ bottom: 1200, top: 1200 }}
|
||||||
const { deleted, locked, removed } = post || {};
|
totalCount={feed?.length || 0}
|
||||||
const isThreadClosed = deleted || locked || removed;
|
data={feed}
|
||||||
|
itemContent={(index, post) => {
|
||||||
|
const { deleted, locked, removed } = post || {};
|
||||||
|
const isThreadClosed = deleted || locked || removed;
|
||||||
|
|
||||||
return <Post index={index} post={post} openReplyModal={isThreadClosed ? () => alert(t('thread_closed_alert')) : openReplyModal} />;
|
return <Post index={index} post={post} openReplyModal={isThreadClosed ? () => alert(t('thread_closed_alert')) : openReplyModal} />;
|
||||||
}}
|
}}
|
||||||
useWindowScroll={true}
|
useWindowScroll={true}
|
||||||
components={{ Footer }}
|
components={{ Footer }}
|
||||||
endReached={loadMore}
|
endReached={loadMore}
|
||||||
ref={virtuosoRef}
|
ref={virtuosoRef}
|
||||||
restoreStateFrom={lastVirtuosoState}
|
restoreStateFrom={lastVirtuosoState}
|
||||||
initialScrollTop={lastVirtuosoState?.scrollTop}
|
initialScrollTop={lastVirtuosoState?.scrollTop}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { useAccount, Subplebbit, useFeed, useSubplebbit } from '@plebbit/plebbit-react-hooks';
|
import { useAccount, Subplebbit, useFeed, useSubplebbit } from '@plebbit/plebbit-react-hooks';
|
||||||
import { Virtuoso, VirtuosoHandle, StateSnapshot } from 'react-virtuoso';
|
import { Virtuoso, VirtuosoHandle, StateSnapshot } from 'react-virtuoso';
|
||||||
import { isAllView, isSubscriptionsView } from '../../lib/utils/view-utils';
|
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 { useDefaultSubplebbitAddresses } from '../../hooks/use-default-subplebbits';
|
||||||
import useFeedStateString from '../../hooks/use-feed-state-string';
|
import useFeedStateString from '../../hooks/use-feed-state-string';
|
||||||
import { useMultisubMetadata } from '../../hooks/use-default-subplebbits';
|
import { useMultisubMetadata } from '../../hooks/use-default-subplebbits';
|
||||||
@@ -16,7 +18,7 @@ import _ from 'lodash';
|
|||||||
|
|
||||||
const lastVirtuosoStates: { [key: string]: StateSnapshot } = {};
|
const lastVirtuosoStates: { [key: string]: StateSnapshot } = {};
|
||||||
|
|
||||||
const useFeedRows = (columnCount: number, feed: any, isFeedLoaded: boolean, subplebbit: Subplebbit) => {
|
const useFeedRows = (columnCount: number, feed: any, isFeedLoaded: boolean, subplebbit: Subplebbit, includeDescriptionAndRules: boolean) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { address, createdAt, description, rules, shortAddress, suggested, title } = subplebbit || {};
|
const { address, createdAt, description, rules, shortAddress, suggested, title } = subplebbit || {};
|
||||||
const { avatarUrl } = suggested || {};
|
const { avatarUrl } = suggested || {};
|
||||||
@@ -29,7 +31,7 @@ const useFeedRows = (columnCount: number, feed: any, isFeedLoaded: boolean, subp
|
|||||||
if (!isFeedLoaded) {
|
if (!isFeedLoaded) {
|
||||||
return []; // prevent rules and description from appearing while feed is loading
|
return []; // prevent rules and description from appearing while feed is loading
|
||||||
}
|
}
|
||||||
if (!description && !rules && !isInAllView) {
|
if (!includeDescriptionAndRules || (!description && !rules && !isInAllView)) {
|
||||||
return feed;
|
return feed;
|
||||||
}
|
}
|
||||||
const _feed = [...feed];
|
const _feed = [...feed];
|
||||||
@@ -59,7 +61,7 @@ const useFeedRows = (columnCount: number, feed: any, isFeedLoaded: boolean, subp
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
return _feed;
|
return _feed;
|
||||||
}, [feed, description, rules, address, isFeedLoaded, createdAt, title, shortAddress, avatarUrl, t, isInAllView, multisub]);
|
}, [feed, description, rules, address, isFeedLoaded, createdAt, title, shortAddress, avatarUrl, t, isInAllView, multisub, includeDescriptionAndRules]);
|
||||||
|
|
||||||
// Memoize rows calculation, ensuring it updates on changes to the modified feed or column count
|
// Memoize rows calculation, ensuring it updates on changes to the modified feed or column count
|
||||||
const rows = useMemo(() => {
|
const rows = useMemo(() => {
|
||||||
@@ -102,8 +104,25 @@ const Catalog = () => {
|
|||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const postsPerPage = useMemo(() => (columnCount <= 2 ? 10 : columnCount === 3 ? 15 : columnCount === 4 ? 20 : 25), []);
|
const postsPerPage = useMemo(() => (columnCount <= 2 ? 10 : columnCount === 3 ? 15 : columnCount === 4 ? 20 : 25), []);
|
||||||
|
|
||||||
|
const blockedComments = useBlockedComments(subplebbitAddress);
|
||||||
|
const blockedCommentsAddresses = useMemo(() => blockedComments.map((comment) => comment.cid), [blockedComments]);
|
||||||
|
|
||||||
const { feed, hasMore, loadMore } = useFeed({ subplebbitAddresses, sortType: 'active', postsPerPage });
|
const { feed, hasMore, loadMore } = useFeed({ subplebbitAddresses, sortType: 'active', postsPerPage });
|
||||||
|
|
||||||
|
const filteredFeed = useMemo(() => feed.filter((comment) => !blockedCommentsAddresses.includes(comment.cid)), [feed, blockedCommentsAddresses]);
|
||||||
|
|
||||||
|
const { resetShowBlockedComments, showBlockedComments, setShowBlockedComments } = useBlockedCommentsStore();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
resetShowBlockedComments();
|
||||||
|
}, [subplebbitAddress, resetShowBlockedComments]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (blockedComments.length === 0) {
|
||||||
|
setShowBlockedComments(false);
|
||||||
|
}
|
||||||
|
}, [blockedComments, setShowBlockedComments]);
|
||||||
|
|
||||||
const subplebbit = useSubplebbit({ subplebbitAddress });
|
const subplebbit = useSubplebbit({ subplebbitAddress });
|
||||||
const { shortAddress, state, title } = subplebbit || {};
|
const { shortAddress, state, title } = subplebbit || {};
|
||||||
const loadingStateString = useFeedStateString(subplebbitAddresses) || t('loading');
|
const loadingStateString = useFeedStateString(subplebbitAddresses) || t('loading');
|
||||||
@@ -121,7 +140,7 @@ const Catalog = () => {
|
|||||||
|
|
||||||
const Footer = () => {
|
const Footer = () => {
|
||||||
let footerContent;
|
let footerContent;
|
||||||
if (feed.length === 0) {
|
if ((showBlockedComments ? blockedComments : filteredFeed).length === 0) {
|
||||||
footerContent = t('no_posts');
|
footerContent = t('no_posts');
|
||||||
}
|
}
|
||||||
if (hasMore || subplebbitAddresses.length === 0) {
|
if (hasMore || subplebbitAddresses.length === 0) {
|
||||||
@@ -130,10 +149,9 @@ const Catalog = () => {
|
|||||||
return <div className={styles.footer}>{footerContent}</div>;
|
return <div className={styles.footer}>{footerContent}</div>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const isFeedloaded = feed.length > 0 || state === 'failed';
|
const isFeedLoaded = (showBlockedComments ? blockedComments : filteredFeed).length > 0 || state === 'failed';
|
||||||
|
|
||||||
// split feed into rows
|
const rows = useFeedRows(columnCount, showBlockedComments ? blockedComments : filteredFeed, isFeedLoaded, subplebbit, !showBlockedComments);
|
||||||
const rows = useFeedRows(columnCount, feed, isFeedloaded, subplebbit);
|
|
||||||
|
|
||||||
// save the last Virtuoso state to restore it when navigating back
|
// save the last Virtuoso state to restore it when navigating back
|
||||||
const virtuosoRef = useRef<VirtuosoHandle | null>(null);
|
const virtuosoRef = useRef<VirtuosoHandle | null>(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user