diff --git a/src/components/post/post-desktop/post-desktop.tsx b/src/components/post/post-desktop/post-desktop.tsx index 73370e68..e8701a00 100644 --- a/src/components/post/post-desktop/post-desktop.tsx +++ b/src/components/post/post-desktop/post-desktop.tsx @@ -1,8 +1,8 @@ -import { useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; import { useLocation, useParams } from 'react-router-dom'; import { Link } from 'react-router-dom'; -import { Comment, useAccount, useBlock, useEditedComment } from '@plebbit/plebbit-react-hooks'; +import { Comment, useAccount, useBlock } from '@plebbit/plebbit-react-hooks'; import Plebbit from '@plebbit/plebbit-js/dist/browser/index.js'; import styles from '../post.module.css'; import { getCommentMediaInfo, getDisplayMediaInfoType, getHasThumbnail } from '../../../lib/utils/media-utils'; @@ -225,14 +225,8 @@ const PostMessage = ({ post }: PostProps) => { }; const PostDesktop = ({ openReplyModal, post, roles, showAllReplies }: PostProps) => { - // handle pending mod or author edit - const { editedComment } = useEditedComment({ comment: post }); - if (editedComment) { - post = editedComment; - } const { cid, content, link, pinned, replyCount, subplebbitAddress } = post || {}; const { isDescription, isRules } = post || {}; // custom properties, not from api - const params = useParams(); const location = useLocation(); const isInPendingPostView = isPendingPostView(location.pathname, params); @@ -247,6 +241,16 @@ const PostDesktop = ({ openReplyModal, post, roles, showAllReplies }: PostProps) const repliesCount = pinned ? replyCount : replyCount - 5; const linksCount = pinned ? totallinksCount : totallinksCount - visiblelinksCount; + const replyRefs = useRef<(HTMLDivElement | null)[]>([]); + + useEffect(() => { + const replyIndex = replies.findIndex((reply) => location.pathname.startsWith(`/p/${subplebbitAddress}/c/${reply?.cid}`)); + + if (replyIndex !== -1 && replyRefs.current[replyIndex]) { + replyRefs.current[replyIndex]?.scrollIntoView(); + } + }, [location.pathname, replies, subplebbitAddress]); + return (