From 24c1957fb95e93da7baa3597ca5a8df41615a38c Mon Sep 17 00:00:00 2001 From: YasinOnm08 Date: Wed, 18 Sep 2024 15:52:51 +0200 Subject: [PATCH] fix convo fr fr --- app/ConversationFrontend.tsx | 18 +++++++-- app/InputBackend.tsx | 74 +++++++++++++++++++----------------- 2 files changed, 53 insertions(+), 39 deletions(-) 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 */} +