mirror of
https://github.com/aljazceru/AgentGPT.git
synced 2025-12-17 14:04:25 +01:00
🚀 Scroll to bottom
This commit is contained in:
@@ -1,13 +1,23 @@
|
||||
import cx from "classnames";
|
||||
import type { ReactNode } from "react";
|
||||
import React from "react";
|
||||
import React, { useEffect, useRef } from "react";
|
||||
|
||||
interface ChatWindowProps {
|
||||
children?: ReactNode;
|
||||
className: string;
|
||||
messages: Message[];
|
||||
}
|
||||
|
||||
const ChatWindow = ({ children, className }: ChatWindowProps) => {
|
||||
const ChatWindow = ({ messages, children, className }: ChatWindowProps) => {
|
||||
const scrollRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
// Scroll to bottom on re-renders
|
||||
if (scrollRef && scrollRef.current) {
|
||||
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<div
|
||||
className={
|
||||
@@ -16,7 +26,13 @@ const ChatWindow = ({ children, className }: ChatWindowProps) => {
|
||||
}
|
||||
>
|
||||
<MacWindowHeader />
|
||||
<div className="mb-3 mr-3 overflow-y-auto sm:h-[10em] 2xl:h-[20em]">
|
||||
<div
|
||||
className="mb-3 mr-3 overflow-y-auto sm:h-[10em] 2xl:h-[20em]"
|
||||
ref={scrollRef}
|
||||
>
|
||||
{messages.map((message, index) => (
|
||||
<ChatMessage key={`${index}-${message.type}`} message={message} />
|
||||
))}
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -62,14 +62,12 @@ const Home: NextPage = () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ChatWindow className="m-10">
|
||||
{messages.map((message, index) => (
|
||||
<ChatWindow className="m-10" messages={messages}>
|
||||
{loading ? (
|
||||
<ChatMessage
|
||||
key={`${index}-${message.type}`}
|
||||
message={message}
|
||||
message={{ type: "action", value: "🧠 Thinking..." }}
|
||||
/>
|
||||
))}
|
||||
{loading ? <div>LOADING...</div> : null}
|
||||
) : null}
|
||||
</ChatWindow>
|
||||
|
||||
<Input
|
||||
|
||||
Reference in New Issue
Block a user