mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix: incorrect pathname check would scroll to reply unexpectedly
This commit is contained in:
@@ -232,7 +232,7 @@ const PostDesktop = ({ openReplyModal, post, roles, showAllReplies, showReplies
|
|||||||
// scroll to reply if pathname is reply permalink (backlink)
|
// scroll to reply if pathname is reply permalink (backlink)
|
||||||
const replyRefs = useRef<(HTMLDivElement | null)[]>([]);
|
const replyRefs = useRef<(HTMLDivElement | null)[]>([]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const replyIndex = replies.findIndex((reply) => location.pathname.startsWith(`/p/${subplebbitAddress}/c/${reply?.cid}`));
|
const replyIndex = replies.findIndex((reply) => location.pathname === `/p/${subplebbitAddress}/c/${reply?.cid}`);
|
||||||
if (replyIndex !== -1 && replyRefs.current[replyIndex]) {
|
if (replyIndex !== -1 && replyRefs.current[replyIndex]) {
|
||||||
replyRefs.current[replyIndex]?.scrollIntoView();
|
replyRefs.current[replyIndex]?.scrollIntoView();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,11 +183,10 @@ const PostMobile = ({ openReplyModal, post, roles, showAllReplies, showReplies =
|
|||||||
const linksCount = useCountLinksInReplies(post);
|
const linksCount = useCountLinksInReplies(post);
|
||||||
const replies = useReplies(post);
|
const replies = useReplies(post);
|
||||||
|
|
||||||
|
// scroll to reply if pathname is reply permalink (backlink)
|
||||||
const replyRefs = useRef<(HTMLDivElement | null)[]>([]);
|
const replyRefs = useRef<(HTMLDivElement | null)[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const replyIndex = replies.findIndex((reply) => location.pathname.startsWith(`/p/${subplebbitAddress}/c/${reply?.cid}`));
|
const replyIndex = replies.findIndex((reply) => location.pathname === `/p/${subplebbitAddress}/c/${reply?.cid}`);
|
||||||
|
|
||||||
if (replyIndex !== -1 && replyRefs.current[replyIndex]) {
|
if (replyIndex !== -1 && replyRefs.current[replyIndex]) {
|
||||||
replyRefs.current[replyIndex]?.scrollIntoView();
|
replyRefs.current[replyIndex]?.scrollIntoView();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { useMemo, useCallback } from 'react';
|
|||||||
import { Comment, useAccountComments } from '@plebbit/plebbit-react-hooks';
|
import { Comment, useAccountComments } from '@plebbit/plebbit-react-hooks';
|
||||||
import { flattenCommentsPages } from '@plebbit/plebbit-react-hooks/dist/lib/utils';
|
import { flattenCommentsPages } from '@plebbit/plebbit-react-hooks/dist/lib/utils';
|
||||||
|
|
||||||
const useRepliesAndAccountReplies = (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]);
|
||||||
|
|
||||||
@@ -45,4 +45,4 @@ const useRepliesAndAccountReplies = (comment: Comment) => {
|
|||||||
return repliesAndNotYetPublishedReplies;
|
return repliesAndNotYetPublishedReplies;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useRepliesAndAccountReplies;
|
export default useReplies;
|
||||||
|
|||||||
Reference in New Issue
Block a user