diff --git a/raggr-frontend/src/components/ChatScreen.tsx b/raggr-frontend/src/components/ChatScreen.tsx index 0beafb8..be0f498 100644 --- a/raggr-frontend/src/components/ChatScreen.tsx +++ b/raggr-frontend/src/components/ChatScreen.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react"; +import { useEffect, useState, useRef } from "react"; import { conversationService } from "../api/conversationService"; import { QuestionBubble } from "./QuestionBubble"; import { AnswerBubble } from "./AnswerBubble"; @@ -39,8 +39,13 @@ export const ChatScreen = ({ setAuthenticated }: ChatScreenProps) => { const [selectedConversation, setSelectedConversation] = useState(null); + const messagesEndRef = useRef(null); const simbaAnswers = ["meow.", "hiss...", "purrrrrr", "yowOWROWWowowr"]; + const scrollToBottom = () => { + messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); + }; + const handleSelectConversation = (conversation: Conversation) => { setShowConversations(false); setSelectedConversation(conversation); @@ -91,6 +96,10 @@ export const ChatScreen = ({ setAuthenticated }: ChatScreenProps) => { loadConversations(); }, []); + useEffect(() => { + scrollToBottom(); + }, [messages]); + useEffect(() => { const loadMessages = async () => { if (selectedConversation == null) return; @@ -203,6 +212,7 @@ export const ChatScreen = ({ setAuthenticated }: ChatScreenProps) => { } return ; })} +