fix(post): clicking the quotelink or backlink to a reply wouldn't scroll to the reply more than once in a row

This commit is contained in:
Tom (plebeius.eth)
2024-08-31 15:19:43 +02:00
parent 0f6b922516
commit e1422d0054
3 changed files with 42 additions and 23 deletions
+1 -10
View File
@@ -341,15 +341,6 @@ const PostMobile = ({ openReplyModal, post, roles, showAllReplies, showReplies =
const isInPostPageView = isPostPageView(location.pathname, params);
const { hidden, unhide } = useHide({ cid });
// scroll to reply if pathname is reply permalink (backlink)
const replyRefs = useRef<(HTMLDivElement | null)[]>([]);
useEffect(() => {
const replyIndex = replies.findIndex((reply) => location.pathname === `/p/${subplebbitAddress}/c/${reply?.cid}`);
if (replyIndex !== -1 && replyRefs.current[replyIndex]) {
replyRefs.current[replyIndex]?.scrollIntoView();
}
}, [location.pathname, replies, subplebbitAddress]);
const stateString = useStateString(post);
return (
@@ -398,7 +389,7 @@ const PostMobile = ({ openReplyModal, post, roles, showAllReplies, showReplies =
replies &&
showReplies &&
(showAllReplies ? replies : replies.slice(-5)).map((reply, index) => (
<div key={index} className={styles.replyContainer} ref={(el) => (replyRefs.current[index] = el)}>
<div key={index} className={styles.replyContainer}>
<Reply openReplyModal={openReplyModal} postReplyCount={replyCount} reply={reply} roles={roles} />
</div>
))}