feat: add backlink highlight and scroll

This commit is contained in:
Tom (plebeius.eth)
2024-06-04 21:35:22 +02:00
parent cbc99f42b0
commit 1911b623d9
5 changed files with 88 additions and 40 deletions
+16 -2
View File
@@ -1,6 +1,6 @@
import { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { useComment, useSubplebbit } from '@plebbit/plebbit-react-hooks';
import { Comment, useComment, useEditedComment, useSubplebbit } from '@plebbit/plebbit-react-hooks';
import { useLocation, useParams } from 'react-router-dom';
import styles from './post-page.module.css';
import { isDescriptionView, isRulesView, isSettingsView } from '../../lib/utils/view-utils';
@@ -25,7 +25,21 @@ const PostPage = () => {
const { activeCid, closeModal, openReplyModal, showReplyModal, scrollY } = useReplyModal();
const post = useComment({ commentCid });
const comment: Comment = useComment({ commentCid });
// if the comment is a reply, get the parent comment
const postComment = useComment({ commentCid: comment?.postCid });
let post;
if (comment.parentCid) {
post = postComment;
} else {
post = comment;
}
// handle pending mod or author edit
const { editedComment } = useEditedComment({ comment: post });
if (editedComment) {
post = editedComment;
}
const { deleted, locked, removed } = post || {};
const isThreadClosed = deleted || locked || removed;