diff --git a/src/components/post/post-desktop/post-desktop.tsx b/src/components/post/post-desktop/post-desktop.tsx index 31722c71..99919d6c 100644 --- a/src/components/post/post-desktop/post-desktop.tsx +++ b/src/components/post/post-desktop/post-desktop.tsx @@ -232,7 +232,7 @@ const PostDesktop = ({ openReplyModal, post, roles, showAllReplies, showReplies // scroll to reply if pathname is reply permalink (backlink) const replyRefs = useRef<(HTMLDivElement | null)[]>([]); 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]) { replyRefs.current[replyIndex]?.scrollIntoView(); } diff --git a/src/components/post/post-mobile/post-mobile.tsx b/src/components/post/post-mobile/post-mobile.tsx index 8f921abf..b35f4b4b 100644 --- a/src/components/post/post-mobile/post-mobile.tsx +++ b/src/components/post/post-mobile/post-mobile.tsx @@ -183,11 +183,10 @@ const PostMobile = ({ openReplyModal, post, roles, showAllReplies, showReplies = const linksCount = useCountLinksInReplies(post); const replies = useReplies(post); + // scroll to reply if pathname is reply permalink (backlink) const replyRefs = useRef<(HTMLDivElement | null)[]>([]); - 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]) { replyRefs.current[replyIndex]?.scrollIntoView(); } diff --git a/src/hooks/use-replies.ts b/src/hooks/use-replies.ts index 6af6b66b..bc59fc0a 100644 --- a/src/hooks/use-replies.ts +++ b/src/hooks/use-replies.ts @@ -2,7 +2,7 @@ import { useMemo, useCallback } from 'react'; import { Comment, useAccountComments } from '@plebbit/plebbit-react-hooks'; 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 const flattenedReplies = useMemo(() => flattenCommentsPages(comment.replies), [comment.replies]); @@ -45,4 +45,4 @@ const useRepliesAndAccountReplies = (comment: Comment) => { return repliesAndNotYetPublishedReplies; }; -export default useRepliesAndAccountReplies; +export default useReplies;