From 853967f8e7ef0e1182494cfa1987d39b734636ed Mon Sep 17 00:00:00 2001 From: YasinOnm08 Date: Tue, 1 Oct 2024 10:39:21 +0200 Subject: [PATCH] chat scroll trial 1 --- app/backend/InputOutputHandler.tsx | 4 +++- app/components/ConversationFrontend.tsx | 28 +++++++++++++------------ 2 files changed, 18 insertions(+), 14 deletions(-) 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 */} -
+