"auto-scroll down when new messages appear "
This commit is contained in:
parent
8ba67f1080
commit
5c744c2987
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 React from "react";
|
||||||
|
import { useRef } from "react";
|
||||||
function MessageBubble({ message }) {
|
function MessageBubble({ message }) {
|
||||||
const isUser = message.role === "user";
|
const isUser = message.role === "user";
|
||||||
return (
|
return (
|
||||||
|
|
@ -16,6 +16,15 @@ function MessageBubble({ message }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ChatWindow({ messages }) {
|
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 (
|
return (
|
||||||
<main className="flex-1 overflow-auto p-2 bg-gradient-to-b from-slate-900 to-slate-800">
|
<main className="flex-1 overflow-auto p-2 bg-gradient-to-b from-slate-900 to-slate-800">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue