From bc469d30b3f00065e5d75d465c4984a8727bab7a Mon Sep 17 00:00:00 2001 From: nzambello Date: Tue, 24 Dec 2024 11:58:25 +0200 Subject: [PATCH] refactor: new scroll logic by last user msg --- src/components/Chat/Chat.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/components/Chat/Chat.tsx b/src/components/Chat/Chat.tsx index 10fc761..fe497af 100644 --- a/src/components/Chat/Chat.tsx +++ b/src/components/Chat/Chat.tsx @@ -131,12 +131,10 @@ const Chat: React.FC = ({ }) => { const scrollToBottom = () => { setTimeout(() => { - document - .querySelector('.memori-chat--content') - ?.scrollTo( - 0, - document.querySelector('.memori-chat--content')?.scrollHeight ?? 0 - ); + let userMsgs = document.querySelectorAll( + '.memori-chat--bubble-container.memori-chat--bubble-from-user' + ); + userMsgs[userMsgs.length - 1].scrollIntoView(); }, 200); }; useEffect(() => {