From 31e912aac3ec95b9805945f47e7fc3aac49206db Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Wed, 16 Oct 2024 09:53:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=82=B9=E5=87=BB=E6=B8=85=E9=99=A4?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87=E7=9B=B4=E6=8E=A5=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E5=88=B0=E6=9C=80=E4=B8=8B=E9=9D=A2=20#192?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #192 --- src/renderer/src/pages/home/Messages/Messages.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/pages/home/Messages/Messages.tsx b/src/renderer/src/pages/home/Messages/Messages.tsx index 259e719324..7b1078f884 100644 --- a/src/renderer/src/pages/home/Messages/Messages.tsx +++ b/src/renderer/src/pages/home/Messages/Messages.tsx @@ -87,16 +87,17 @@ const Messages: FC = ({ assistant, topic, setActiveTopic }) => { [messages, topic.id] ) + const scrollToBottom = useCallback(() => { + setTimeout(() => containerRef.current?.scrollTo({ top: containerRef.current.scrollHeight, behavior: 'auto' }), 10) + }, []) + useEffect(() => { const unsubscribes = [ EventEmitter.on(EVENT_NAMES.SEND_MESSAGE, async (msg: Message) => { await onSendMessage(msg) // Scroll to bottom - setTimeout( - () => containerRef.current?.scrollTo({ top: containerRef.current.scrollHeight, behavior: 'auto' }), - 10 - ) + scrollToBottom() // Fetch completion fetchChatCompletion({ @@ -146,6 +147,7 @@ const Messages: FC = ({ assistant, topic, setActiveTopic }) => { if (lastMessage && lastMessage.type === 'clear') { onDeleteMessage(lastMessage) + scrollToBottom() return } @@ -163,6 +165,8 @@ const Messages: FC = ({ assistant, topic, setActiveTopic }) => { status: 'success', type: 'clear' } as Message) + + scrollToBottom() }), EventEmitter.on(EVENT_NAMES.NEW_BRANCH, async (index: number) => { const newTopic = getDefaultTopic(assistant.id) @@ -192,6 +196,7 @@ const Messages: FC = ({ assistant, topic, setActiveTopic }) => { messages, onDeleteMessage, onSendMessage, + scrollToBottom, setActiveTopic, topic, updateTopic