diff --git a/app/backend/InputOutputHandler.tsx b/app/backend/InputOutputHandler.tsx index 646e924..b4a59b7 100644 --- a/app/backend/InputOutputHandler.tsx +++ b/app/backend/InputOutputHandler.tsx @@ -1,6 +1,6 @@ "use client" import React, { use, useEffect, useRef, useState } from "react"; -import ConversationFrontend from "../components/ConversationFrontend"; +import ConversationFrontend from '../components/ConversationFrontend'; import InputFrontend from "../components/InputFrontend"; import { sendToVoiceRecognition } from "./voice_backend" import axios from "axios"; @@ -52,6 +52,7 @@ const InputOutputBackend: React.FC = () => { }, [preferredCurrency, preferredLanguage, timeFormat, dateFormat, preferredMeasurement, timeZone]); + const conversationRef = useRef(null) const [copyClicked, setCopyClicked] = useState(false) const [accessToken, setAccessToken] = useState("") const postWorkerRef = useRef(null) @@ -266,6 +267,7 @@ const InputOutputBackend: React.FC = () => { return ( <> ( - ({ messages, onResendClick, onEditClick, onCopyClick, isClicked}, ref: ForwardedRef) => { - const endOfMessagesRef = useRef(null); - + ({ messages, onResendClick, onEditClick, onCopyClick, isClicked }, ref: ForwardedRef) => { + + useEffect(() => { + if (ref && typeof ref !== 'function') { + const element = ref as React.RefObject; + if (element.current) { + element.current.scrollTop = element.current.scrollHeight; + } + } + }, [messages, ref]); + return ( -
-
+
+
{messages.map((message, index) => { - let isUserMessage - if (message.role == "user") { - isUserMessage = message - } if (index >= 1){ return (

{message.content}

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