fix replycount of description post

This commit is contained in:
Tom (plebeius.eth)
2024-09-18 12:37:39 +02:00
parent 63750fb990
commit dcd970c706
4 changed files with 9 additions and 4 deletions
@@ -1,6 +1,6 @@
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { Link, useLocation, useNavigate, useParams } from 'react-router-dom'; import { Link, useLocation, useNavigate, useParams } from 'react-router-dom';
import { useAccountComment, useComment, useSubscribe } from '@plebbit/plebbit-react-hooks'; import { useAccountComment, useComment, useSubplebbit, useSubscribe } from '@plebbit/plebbit-react-hooks';
import { isAllView, isCatalogView, isDescriptionView, isPendingPostView, isPostPageView, isSubscriptionsView } from '../../lib/utils/view-utils'; import { isAllView, isCatalogView, isDescriptionView, isPendingPostView, isPostPageView, isSubscriptionsView } from '../../lib/utils/view-utils';
import useCatalogStyleStore from '../../stores/use-catalog-style-store'; import useCatalogStyleStore from '../../stores/use-catalog-style-store';
import useFeedResetStore from '../../stores/use-feed-reset-store'; import useFeedResetStore from '../../stores/use-feed-reset-store';
@@ -291,10 +291,12 @@ const PostPageStats = () => {
const isInDescriptionView = isDescriptionView(location.pathname, params); const isInDescriptionView = isDescriptionView(location.pathname, params);
const comment = useComment({ commentCid: params?.commentCid }); const comment = useComment({ commentCid: params?.commentCid });
const subplebbit = useSubplebbit({ subplebbitAddress: params?.subplebbitAddress });
const descriptionReplyCount = location?.pathname.startsWith('/p/all/') ? 0 : subplebbit?.rules?.length > 0 ? 1 : 0;
const { closed, pinned, replyCount } = comment || {}; const { closed, pinned, replyCount } = comment || {};
const linkCount = useCountLinksInReplies(comment); const linkCount = useCountLinksInReplies(comment);
const displayReplyCount = replyCount !== undefined ? replyCount.toString() : isInDescriptionView ? 1 : '?'; const displayReplyCount = replyCount !== undefined ? replyCount.toString() : isInDescriptionView ? descriptionReplyCount : '?';
const replyCountTooltip = replyCount !== undefined || isInDescriptionView ? _.capitalize(t('replies')) : t('loading'); const replyCountTooltip = replyCount !== undefined || isInDescriptionView ? _.capitalize(t('replies')) : t('loading');
return ( return (
@@ -8,12 +8,13 @@ interface DescriptionPostProps {
avatarUrl?: string; avatarUrl?: string;
createdAt: number; createdAt: number;
description: string; description: string;
replyCount: number;
shortAddress: string; shortAddress: string;
subplebbitAddress: string | undefined; subplebbitAddress: string | undefined;
title: string; title: string;
} }
const SubplebbitDescription = ({ avatarUrl, createdAt, description, shortAddress, subplebbitAddress, title }: DescriptionPostProps) => { const SubplebbitDescription = ({ avatarUrl, createdAt, description, replyCount, shortAddress, subplebbitAddress, title }: DescriptionPostProps) => {
const { t } = useTranslation(); const { t } = useTranslation();
const location = useLocation(); const location = useLocation();
const isInAllView = isAllView(location.pathname, useParams()); const isInAllView = isAllView(location.pathname, useParams());
@@ -26,7 +27,7 @@ const SubplebbitDescription = ({ avatarUrl, createdAt, description, shortAddress
author: { displayName: `## ${t('board_mods')}` }, author: { displayName: `## ${t('board_mods')}` },
content: isInAllView ? multisubMetadata?.description : description, content: isInAllView ? multisubMetadata?.description : description,
link: avatarUrl, link: avatarUrl,
replyCount: 1, replyCount,
title: t('welcome_to_board', { title: t('welcome_to_board', {
board: isInAllView ? multisubMetadata?.title : title || `p/${shortAddress}`, board: isInAllView ? multisubMetadata?.title : title || `p/${shortAddress}`,
interpolation: { escapeValue: false }, interpolation: { escapeValue: false },
+1
View File
@@ -186,6 +186,7 @@ const Board = () => {
subplebbitAddress={subplebbitAddress} subplebbitAddress={subplebbitAddress}
createdAt={createdAt} createdAt={createdAt}
description={description} description={description}
replyCount={isInAllView ? 0 : rules?.length > 0 ? 1 : 0}
shortAddress={shortAddress} shortAddress={shortAddress}
title={title} title={title}
/> />
+1
View File
@@ -109,6 +109,7 @@ const PostPage = () => {
avatarUrl={suggested?.avatarUrl} avatarUrl={suggested?.avatarUrl}
createdAt={createdAt} createdAt={createdAt}
description={description} description={description}
replyCount={location.pathname.startsWith('/p/all/') ? 0 : rules?.length > 0 ? 1 : 0}
subplebbitAddress={subplebbitAddress} subplebbitAddress={subplebbitAddress}
shortAddress={shortAddress} shortAddress={shortAddress}
title={title} title={title}