diff --git a/src/components/board-buttons/board-buttons.tsx b/src/components/board-buttons/board-buttons.tsx index f23db435..f62fd713 100644 --- a/src/components/board-buttons/board-buttons.tsx +++ b/src/components/board-buttons/board-buttons.tsx @@ -1,8 +1,6 @@ -import { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { Link, useLocation, useNavigate, useParams } from 'react-router-dom'; import { useAccountComment, useComment, useSubscribe } from '@plebbit/plebbit-react-hooks'; -import { flattenCommentsPages } from '@plebbit/plebbit-react-hooks/dist/lib/utils'; import { isAllView, isCatalogView, isDescriptionView, isPendingPostView, isPostPageView, isRulesView, isSubscriptionsView } from '../../lib/utils/view-utils'; import useCatalogStyleStore from '../../stores/use-catalog-style-store'; import useFeedResetStore from '../../stores/use-feed-reset-store'; @@ -12,7 +10,6 @@ import CatalogFilters from '../../views/catalog/catalog-filters/'; import styles from './board-buttons.module.css'; import Tooltip from '../tooltip'; import useCountLinksInReplies from '../../hooks/use-count-links-in-replies'; -import useReplyCount from '../../hooks/use-reply-count'; interface BoardButtonsProps { address?: string | undefined; @@ -232,10 +229,8 @@ const PostPageStats = () => { const isInRulesView = isRulesView(location.pathname, params); const comment = useComment({ commentCid: params?.commentCid }); - const { closed, pinned } = comment || {}; - + const { closed, pinned, replyCount } = comment || {}; const linkCount = useCountLinksInReplies(comment); - const replyCount = useReplyCount(comment); return ( diff --git a/src/components/catalog-row/catalog-row.tsx b/src/components/catalog-row/catalog-row.tsx index 4a3f33f3..f8981461 100644 --- a/src/components/catalog-row/catalog-row.tsx +++ b/src/components/catalog-row/catalog-row.tsx @@ -12,7 +12,6 @@ import useEditCommentPrivileges from '../../hooks/use-author-privileges'; import useCountLinksInReplies from '../../hooks/use-count-links-in-replies'; import useFetchGifFirstFrame from '../../hooks/use-fetch-gif-first-frame'; import useHide from '../../hooks/use-hide'; -import useReplyCount from '../../hooks/use-reply-count'; import useWindowWidth from '../../hooks/use-window-width'; import PostMenuDesktop from '../post-desktop/post-menu-desktop'; import styles from './catalog-row.module.css'; @@ -96,8 +95,25 @@ export const CatalogPostMedia = ({ commentMediaInfo, isOutOfFeed, linkWidth, lin const CatalogPost = ({ post }: { post: Comment }) => { const { t } = useTranslation(); - const { author, cid, content, isDescription, isRules, lastChildCid, link, linkHeight, linkWidth, locked, pinned, spoiler, subplebbitAddress, timestamp, title } = - post || {}; + const { + author, + cid, + content, + isDescription, + isRules, + lastChildCid, + link, + linkHeight, + linkWidth, + locked, + pinned, + replyCount, + spoiler, + subplebbitAddress, + timestamp, + title, + } = post || {}; + const linkCount = useCountLinksInReplies(post); const commentMediaInfo = getCommentMediaInfo(post); const hasThumbnail = getHasThumbnail(commentMediaInfo, link); const { hidden } = useHide({ cid }); @@ -107,9 +123,6 @@ const CatalogPost = ({ post }: { post: Comment }) => { const postLink = isInAllView && isDescription ? `/p/all/description` : `/p/${subplebbitAddress}/${isDescription ? 'description' : isRules ? 'rules' : `c/${cid}`}`; - const linkCount = useCountLinksInReplies(post); - const replyCount = useReplyCount(post); - const threadIcons = (
{pinned && } diff --git a/src/components/post-desktop/post-desktop.tsx b/src/components/post-desktop/post-desktop.tsx index fa8fca56..616de12e 100644 --- a/src/components/post-desktop/post-desktop.tsx +++ b/src/components/post-desktop/post-desktop.tsx @@ -13,7 +13,6 @@ import useEditCommentPrivileges from '../../hooks/use-author-privileges'; import useCountLinksInReplies from '../../hooks/use-count-links-in-replies'; import useHide from '../../hooks/use-hide'; import useReplies from '../../hooks/use-replies'; -import useReplyCount from '../../hooks/use-reply-count'; import useStateString from '../../hooks/use-state-string'; import CommentMedia from '../comment-media'; import EditMenu from '../edit-menu/edit-menu'; @@ -339,7 +338,7 @@ const Reply = ({ openReplyModal, postReplyCount, reply, roles }: PostProps) => { const PostDesktop = ({ openReplyModal, post, roles, showAllReplies, showReplies = true }: PostProps) => { const { t } = useTranslation(); - const { author, cid, content, link, pinned, postCid, subplebbitAddress } = post || {}; + const { author, cid, content, link, pinned, postCid, replyCount, subplebbitAddress } = post || {}; const { isDescription, isRules } = post || {}; // custom properties, not from api const params = useParams(); const location = useLocation(); @@ -350,7 +349,6 @@ const PostDesktop = ({ openReplyModal, post, roles, showAllReplies, showReplies const isHidden = hidden && !isInPostPageView; const replies = useReplies(post); - const replyCount = useReplyCount(post); const visiblelinksCount = useCountLinksInReplies(post, 5); const totalLinksCount = useCountLinksInReplies(post); const repliesCount = pinned ? replyCount : replyCount - 5; diff --git a/src/components/post-mobile/post-mobile.tsx b/src/components/post-mobile/post-mobile.tsx index 6d014ba3..542fb75d 100644 --- a/src/components/post-mobile/post-mobile.tsx +++ b/src/components/post-mobile/post-mobile.tsx @@ -11,7 +11,6 @@ import useAuthorAddressClick from '../../hooks/use-author-address-click'; import useCountLinksInReplies from '../../hooks/use-count-links-in-replies'; import useHide from '../../hooks/use-hide'; import useReplies from '../../hooks/use-replies'; -import useReplyCount from '../../hooks/use-reply-count'; import useStateString from '../../hooks/use-state-string'; import CommentMedia from '../comment-media'; import LoadingEllipsis from '../loading-ellipsis'; @@ -276,9 +275,8 @@ const Reply = ({ openReplyModal, postReplyCount, reply, roles }: PostProps) => { const PostMobile = ({ openReplyModal, post, roles, showAllReplies, showReplies = true }: PostProps) => { const { t } = useTranslation(); - const { author, cid, content, pinned, postCid, subplebbitAddress } = post || {}; + const { author, cid, content, pinned, postCid, replyCount, subplebbitAddress } = post || {}; const { isDescription, isRules } = post || {}; // custom properties, not from api - const replyCount = useReplyCount(post); const params = useParams(); const location = useLocation(); const isInAllView = isAllView(location.pathname, params); diff --git a/src/hooks/use-reply-count.ts b/src/hooks/use-reply-count.ts deleted file mode 100644 index 9ead7e81..00000000 --- a/src/hooks/use-reply-count.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { useMemo } from 'react'; -import { Comment } from '@plebbit/plebbit-react-hooks'; -import { flattenCommentsPages } from '@plebbit/plebbit-react-hooks/dist/lib/utils'; - -const useReplyCount = (comment: Comment) => { - const replies = comment?.replies; - const flattenedReplies = useMemo(() => flattenCommentsPages(replies), [replies]); - - return flattenedReplies.length; -}; - -export default useReplyCount;