mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
handle undefined values, clarify comment
This commit is contained in:
@@ -4,7 +4,7 @@ import { flattenCommentsPages } from '@plebbit/plebbit-react-hooks/dist/lib/util
|
|||||||
|
|
||||||
const useCountLinksInReplies = (comment: Comment, firstXReplies?: number) => {
|
const useCountLinksInReplies = (comment: Comment, firstXReplies?: number) => {
|
||||||
let linkCount = 0;
|
let linkCount = 0;
|
||||||
const flattenedReplies = useMemo(() => flattenCommentsPages(comment.replies), [comment.replies]);
|
const flattenedReplies = useMemo(() => flattenCommentsPages(comment?.replies), [comment?.replies]);
|
||||||
|
|
||||||
const repliesToConsider = firstXReplies !== undefined ? flattenedReplies.slice(0, firstXReplies) : flattenedReplies;
|
const repliesToConsider = firstXReplies !== undefined ? flattenedReplies.slice(0, firstXReplies) : flattenedReplies;
|
||||||
|
|
||||||
|
|||||||
@@ -4,17 +4,17 @@ import { flattenCommentsPages } from '@plebbit/plebbit-react-hooks/dist/lib/util
|
|||||||
|
|
||||||
const useReplies = (comment: Comment) => {
|
const useReplies = (comment: Comment) => {
|
||||||
// flatten all replies including nested ones from the original comment
|
// flatten all replies including nested ones from the original comment
|
||||||
const flattenedReplies = useMemo(() => flattenCommentsPages(comment.replies), [comment.replies]);
|
const flattenedReplies = useMemo(() => flattenCommentsPages(comment?.replies), [comment?.replies]);
|
||||||
|
|
||||||
// generate a Set of CIDs from flattened replies for quick lookup
|
// generate a Set of CIDs from flattened replies for quick lookup
|
||||||
const replyCids = useMemo(() => new Set(flattenedReplies.map((reply) => reply.cid)), [flattenedReplies]);
|
const replyCids = useMemo(() => new Set(flattenedReplies.map((reply) => reply?.cid)), [flattenedReplies]);
|
||||||
|
|
||||||
// filter against the original comment's CID and all CIDs in flattened replies
|
// filter against the original comment's CID and all CIDs in flattened replies
|
||||||
const filter = useCallback(
|
const filter = useCallback(
|
||||||
(accountComment: Comment) => {
|
(accountComment: Comment) => {
|
||||||
return accountComment.parentCid === comment.cid || replyCids.has(accountComment.parentCid);
|
return accountComment.parentCid === comment?.cid || replyCids.has(accountComment.parentCid);
|
||||||
},
|
},
|
||||||
[comment.cid, replyCids],
|
[comment?.cid, replyCids],
|
||||||
);
|
);
|
||||||
|
|
||||||
const { accountComments } = useAccountComments({ filter });
|
const { accountComments } = useAccountComments({ filter });
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ const useStateString = (commentOrSubplebbit: CommentOrSubplebbit): string | unde
|
|||||||
if (commentOrSubplebbit?.publishingState && commentOrSubplebbit?.publishingState !== 'stopped' && commentOrSubplebbit?.publishingState !== 'succeeded') {
|
if (commentOrSubplebbit?.publishingState && commentOrSubplebbit?.publishingState !== 'stopped' && commentOrSubplebbit?.publishingState !== 'succeeded') {
|
||||||
stateString = commentOrSubplebbit.publishingState;
|
stateString = commentOrSubplebbit.publishingState;
|
||||||
} else if (commentOrSubplebbit?.updatingState !== 'stopped' && commentOrSubplebbit?.updatingState !== 'succeeded') {
|
} else if (commentOrSubplebbit?.updatingState !== 'stopped' && commentOrSubplebbit?.updatingState !== 'succeeded') {
|
||||||
stateString = commentOrSubplebbit.updatingState;
|
stateString = commentOrSubplebbit?.updatingState;
|
||||||
}
|
}
|
||||||
if (stateString) {
|
if (stateString) {
|
||||||
stateString = stateString.replaceAll('-', ' ').replace('ipfs', 'IPFS').replace('ipns', 'IPNS');
|
stateString = stateString.replaceAll('-', ' ').replace('ipfs', 'IPFS').replace('ipns', 'IPNS');
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Comment, Role, useComment, useEditedComment, useSubplebbit } from '@plebbit/plebbit-react-hooks';
|
import { Role, useComment, useEditedComment, useSubplebbit } from '@plebbit/plebbit-react-hooks';
|
||||||
import { useLocation, useParams } from 'react-router-dom';
|
import { useLocation, useParams } from 'react-router-dom';
|
||||||
import { isDescriptionView, isRulesView, isSettingsView } from '../../lib/utils/view-utils';
|
import { isDescriptionView, isRulesView, isSettingsView } from '../../lib/utils/view-utils';
|
||||||
import useIsMobile from '../../hooks/use-is-mobile';
|
import useIsMobile from '../../hooks/use-is-mobile';
|
||||||
@@ -55,8 +55,9 @@ const PostPage = () => {
|
|||||||
|
|
||||||
const { activeCid, closeModal, openReplyModal, showReplyModal, scrollY } = useReplyModal();
|
const { activeCid, closeModal, openReplyModal, showReplyModal, scrollY } = useReplyModal();
|
||||||
|
|
||||||
const comment: Comment = useComment({ commentCid });
|
const comment = useComment({ commentCid });
|
||||||
// if the comment is a reply, get the parent comment
|
|
||||||
|
// if the comment is a reply, return the post comment instead, then the reply will be highlighted in the thread
|
||||||
const postComment = useComment({ commentCid: comment?.postCid });
|
const postComment = useComment({ commentCid: comment?.postCid });
|
||||||
let post;
|
let post;
|
||||||
if (comment.parentCid) {
|
if (comment.parentCid) {
|
||||||
@@ -64,6 +65,7 @@ const PostPage = () => {
|
|||||||
} else {
|
} else {
|
||||||
post = comment;
|
post = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle pending mod or author edit
|
// handle pending mod or author edit
|
||||||
const { editedComment } = useEditedComment({ comment: post });
|
const { editedComment } = useEditedComment({ comment: post });
|
||||||
if (editedComment) {
|
if (editedComment) {
|
||||||
|
|||||||
Reference in New Issue
Block a user