diff --git a/app/ConversationFrontend.tsx b/app/ConversationFrontend.tsx index d268bfb..b6bd312 100644 --- a/app/ConversationFrontend.tsx +++ b/app/ConversationFrontend.tsx @@ -1,4 +1,4 @@ -import React, { ForwardedRef } from 'react'; +import React, { ForwardedRef, useEffect, useRef } from 'react'; interface ConversationProps { messages: string[]; @@ -9,22 +9,32 @@ interface ConversationProps { const ConversationFrontend = React.forwardRef( ({ messages, onResendClick, onEditClick, onCopyClick }, ref: ForwardedRef) => { + const endOfMessagesRef = useRef(null); + + // Auto-scroll to the bottom of the conversation whenever a new message is added + useEffect(() => { + if (endOfMessagesRef.current) { + endOfMessagesRef.current.scrollIntoView({ behavior: 'smooth' }); + } + }, [messages]); // Triggers the effect whenever the 'messages' array changes + return (
{messages.map((message, index) => { const isUserMessage = message.startsWith('User:'); + console.log("output: "+messages) return (
-

- {message} -

+

{message}

); })} + {/* Dummy div to mark the end of the conversation for auto-scrolling */} +