From 1da21fabeeaf30c4b814795063ea808a98759f5a Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Mon, 27 Oct 2025 12:12:05 -0400 Subject: [PATCH] Add auto-scroll to bottom for new messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Automatically scroll to latest message when new messages arrive - Uses smooth scrolling behavior for better UX - Triggers on message array changes - Improves chat experience by keeping conversation in view 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- raggr-frontend/src/components/ChatScreen.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 ; })} +