diff --git a/src/frontend/src/components/public/CommentsSidebar/index.tsx b/src/frontend/src/components/public/CommentsSidebar/index.tsx index 344d25d24..9d3c5a820 100644 --- a/src/frontend/src/components/public/CommentsSidebar/index.tsx +++ b/src/frontend/src/components/public/CommentsSidebar/index.tsx @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useState } from 'react'; +import { useCallback, useEffect, useRef, useState } from 'react'; import CommentSidebarProps, { Comment } from './interfaces'; import { getDateTime, stringToDate } from '../../../utils/date'; import { faEllipsisH } from '@fortawesome/free-solid-svg-icons'; @@ -29,6 +29,7 @@ const CommentSidebar = ({ const [modalParagraph, setModalParagraph] = useState(''); const [modalButtonValue, setModalButtonValue] = useState(''); const [enableComments, setEnableComments] = useState(false); + const commentsEndRef = useRef(null); useEffect(() => { if (!pia?.status) return; @@ -69,6 +70,16 @@ const CommentSidebar = ({ setComments([]); }, [pathname]); + useEffect(() => { + if (commentsEndRef.current) { + const scrollHeight = commentsEndRef.current.scrollHeight; + commentsEndRef.current.scrollTo({ + top: scrollHeight, + behavior: 'smooth', + }); + } + }, [comments]); + const handleModalClose = async (event: any) => { event.preventDefault(); setShowModal(false); @@ -115,7 +126,10 @@ const CommentSidebar = ({ <>

Comments

-
+
{comments && comments?.map((comment) => (