mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
Scroll to bottom of messages on new messages state change (#230)
Co-authored-by: George Balch <george.balch@proton.me>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useState } from "react";
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import "./ChatInterface.css";
|
||||
import userAvatar from "../assets/user-avatar.png";
|
||||
@@ -7,8 +7,13 @@ import { RootState } from "../store";
|
||||
import { sendChatMessage } from "../services/chatService";
|
||||
|
||||
function MessageList(): JSX.Element {
|
||||
const messagesEndRef = useRef<HTMLDivElement>(null);
|
||||
const { messages } = useSelector((state: RootState) => state.chat);
|
||||
|
||||
useEffect(() => {
|
||||
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
||||
}, [messages]);
|
||||
|
||||
return (
|
||||
<div className="message-list">
|
||||
{messages.map((msg, index) => (
|
||||
@@ -25,6 +30,7 @@ function MessageList(): JSX.Element {
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<div ref={messagesEndRef} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user