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 cx from "classnames";
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import React from "react";
|
import React, { useEffect, useRef } from "react";
|
||||||
|
|
||||||
interface ChatWindowProps {
|
interface ChatWindowProps {
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
className: string;
|
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 (
|
return (
|
||||||
<div
|
<div
|
||||||
className={
|
className={
|
||||||
@@ -16,7 +26,13 @@ const ChatWindow = ({ children, className }: ChatWindowProps) => {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<MacWindowHeader />
|
<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}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -62,14 +62,12 @@ const Home: NextPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ChatWindow className="m-10">
|
<ChatWindow className="m-10" messages={messages}>
|
||||||
{messages.map((message, index) => (
|
{loading ? (
|
||||||
<ChatMessage
|
<ChatMessage
|
||||||
key={`${index}-${message.type}`}
|
message={{ type: "action", value: "🧠 Thinking..." }}
|
||||||
message={message}
|
|
||||||
/>
|
/>
|
||||||
))}
|
) : null}
|
||||||
{loading ? <div>LOADING...</div> : null}
|
|
||||||
</ChatWindow>
|
</ChatWindow>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
|
|||||||
Reference in New Issue
Block a user