diff --git a/src/components/Article/CommentsTree.tsx b/src/components/Article/CommentsTree.tsx index 3057ffb6..03a39287 100644 --- a/src/components/Article/CommentsTree.tsx +++ b/src/components/Article/CommentsTree.tsx @@ -66,9 +66,6 @@ export const CommentsTree = (props: Props) => { if (commentsOrder() === 'rating') { newSortedComments = newSortedComments.sort(sortCommentsByRating) } - - newSortedComments.reverse() - return newSortedComments }) diff --git a/src/components/Article/FullArticle.tsx b/src/components/Article/FullArticle.tsx index 46177b8c..1bb30930 100644 --- a/src/components/Article/FullArticle.tsx +++ b/src/components/Article/FullArticle.tsx @@ -58,9 +58,8 @@ export type ArticlePageSearchParams = { const scrollTo = (el: HTMLElement) => { const { top } = el.getBoundingClientRect() - window.scrollTo({ - top: top + window.scrollY - DEFAULT_HEADER_OFFSET, + top: top - DEFAULT_HEADER_OFFSET, left: 0, behavior: 'smooth', }) @@ -152,22 +151,16 @@ export const FullArticle = (props: Props) => { current: HTMLDivElement } = { current: null } - const scrollToComments = () => { - scrollTo(commentsRef.current) - } - createEffect(() => { if (props.scrollToComments) { - scrollToComments() + scrollTo(commentsRef.current) } }) createEffect(() => { if (searchParams()?.scrollTo === 'comments' && commentsRef.current) { - scrollToComments() - changeSearchParams({ - scrollTo: null, - }) + requestAnimationFrame(() => scrollTo(commentsRef.current)) + changeSearchParams({ scrollTo: null }) } }) @@ -177,10 +170,8 @@ export const FullArticle = (props: Props) => { `[id='comment_${searchParams().commentId}']`, ) - changeSearchParams({ commentId: null }) - if (commentElement) { - scrollTo(commentElement) + requestAnimationFrame(() => scrollTo(commentElement)) } } }) @@ -473,7 +464,11 @@ export const FullArticle = (props: Props) => { {(triggerRef: (el) => void) => ( -
+
scrollTo(commentsRef.current)} + > = Record< } const clearSearchParams = (replace = false) => { - searchParamsStore.open({}, replace) + // searchParamsStore.open({}, replace) } return {