Spaces:
Running
Running
Commit ·
01bbc8b
1
Parent(s): 7db2a6d
code updated to fix the scroll to bottom issue resolved
Browse files- src/components/ChatBox.jsx +13 -5
src/components/ChatBox.jsx
CHANGED
|
@@ -6,11 +6,19 @@ import "./ChatBox.css"; // Add dot animation CSS
|
|
| 6 |
export default function ChatBox({ messages, loading }) {
|
| 7 |
const bottomRef = useRef(null);
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
return (
|
| 16 |
<Box className="chat-box">
|
|
|
|
| 6 |
export default function ChatBox({ messages, loading }) {
|
| 7 |
const bottomRef = useRef(null);
|
| 8 |
|
| 9 |
+
useEffect(() => {
|
| 10 |
+
if (!bottomRef.current) return;
|
| 11 |
+
|
| 12 |
+
if (loading) {
|
| 13 |
+
bottomRef.current.scrollIntoView({ behavior: 'auto' });
|
| 14 |
+
} else {
|
| 15 |
+
// Smooth scroll after streaming ends with slight delay
|
| 16 |
+
setTimeout(() => {
|
| 17 |
+
bottomRef.current?.scrollIntoView({ behavior: 'smooth' });
|
| 18 |
+
}, 80); // tweak timing based on UX
|
| 19 |
+
}
|
| 20 |
+
}, [messages, loading]);
|
| 21 |
+
|
| 22 |
|
| 23 |
return (
|
| 24 |
<Box className="chat-box">
|