"auto-scroll down when new messages appear "
This commit is contained in:
parent
4774b2c8a5
commit
1da5f8e083
2 changed files with 10 additions and 1 deletions
0
src/components/layouts/dashboard-layout.jsx
Normal file
0
src/components/layouts/dashboard-layout.jsx
Normal file
|
|
@ -1,5 +1,5 @@
|
|||
import React from "react";
|
||||
|
||||
import { useRef } from "react";
|
||||
function MessageBubble({ message }) {
|
||||
const isUser = message.role === "user";
|
||||
return (
|
||||
|
|
@ -16,6 +16,15 @@ function MessageBubble({ message }) {
|
|||
}
|
||||
|
||||
export default function ChatWindow({ messages }) {
|
||||
const chatRef = useRef(null);
|
||||
// Auto-scroll to bottom when new messages appear
|
||||
useEffect(() => {
|
||||
chatRef.current?.scrollTo({
|
||||
top: chatRef.current.scrollHeight,
|
||||
behavior: "smooth",
|
||||
});
|
||||
}, [messages]);
|
||||
|
||||
return (
|
||||
<main className="flex-1 overflow-auto p-2 bg-gradient-to-b from-slate-900 to-slate-800">
|
||||
<div className="space-y-2">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue