mirror of
https://github.com/aljazceru/AgentGPT.git
synced 2025-12-17 22:14:23 +01:00
🤖 Fix scrolling
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import React, { useEffect, useRef } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
import { FaBrain, FaListAlt, FaPlayCircle, FaStar } from "react-icons/fa";
|
import { FaBrain, FaListAlt, FaPlayCircle, FaStar } from "react-icons/fa";
|
||||||
import autoAnimate from "@formkit/auto-animate";
|
import autoAnimate from "@formkit/auto-animate";
|
||||||
import PopIn from "./motions/popin";
|
import PopIn from "./motions/popin";
|
||||||
@@ -11,12 +11,26 @@ interface ChatWindowProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ChatWindow = ({ messages, children, className }: ChatWindowProps) => {
|
const ChatWindow = ({ messages, children, className }: ChatWindowProps) => {
|
||||||
|
const [hasUserScrolled, setHasUserScrolled] = useState(false);
|
||||||
const scrollRef = useRef<HTMLDivElement>(null);
|
const scrollRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
const handleScroll = (event: React.UIEvent<HTMLDivElement>) => {
|
||||||
|
const { scrollTop, scrollHeight, clientHeight } = event.currentTarget;
|
||||||
|
|
||||||
|
// Use has scrolled if we have scrolled up at all from the bottom
|
||||||
|
if (scrollTop < scrollHeight - clientHeight - 10) {
|
||||||
|
setHasUserScrolled(true);
|
||||||
|
} else {
|
||||||
|
setHasUserScrolled(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Scroll to bottom on re-renders
|
// Scroll to bottom on re-renders
|
||||||
if (scrollRef && scrollRef.current) {
|
if (scrollRef && scrollRef.current) {
|
||||||
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
if (!hasUserScrolled) {
|
||||||
|
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -35,6 +49,7 @@ const ChatWindow = ({ messages, children, className }: ChatWindowProps) => {
|
|||||||
<div
|
<div
|
||||||
className="mb-3 mr-3 h-[10em] overflow-y-auto overflow-x-hidden sm-h:h-[15em] md-h:h-[20em] lg-h:h-[30em] "
|
className="mb-3 mr-3 h-[10em] overflow-y-auto overflow-x-hidden sm-h:h-[15em] md-h:h-[20em] lg-h:h-[30em] "
|
||||||
ref={scrollRef}
|
ref={scrollRef}
|
||||||
|
onScroll={handleScroll}
|
||||||
>
|
>
|
||||||
{messages.map((message, index) => (
|
{messages.map((message, index) => (
|
||||||
<ChatMessage key={`${index}-${message.type}`} message={message} />
|
<ChatMessage key={`${index}-${message.type}`} message={message} />
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export default function Dialog({
|
|||||||
goal by thinking of tasks to do, executing them, and
|
goal by thinking of tasks to do, executing them, and
|
||||||
learning from the results 🚀.
|
learning from the results 🚀.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<div>
|
||||||
<br />
|
<br />
|
||||||
This platform is currently in beta, we are currently working
|
This platform is currently in beta, we are currently working
|
||||||
on:
|
on:
|
||||||
@@ -53,12 +53,15 @@ export default function Dialog({
|
|||||||
<li>Interaction with websites and people 👨👩👦</li>
|
<li>Interaction with websites and people 👨👩👦</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p className="mt-2">Follow the journey below:</p>
|
<p className="mt-2">Follow the journey below:</p>
|
||||||
</p>
|
</div>
|
||||||
<div className="mt-4 flex w-full items-center justify-center gap-5">
|
<div className="mt-4 flex w-full items-center justify-center gap-5">
|
||||||
<div
|
<div
|
||||||
className="cursor-pointer rounded-full bg-black/30 p-3 hover:bg-black/70"
|
className="cursor-pointer rounded-full bg-black/30 p-3 hover:bg-black/70"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
window.open("https://twitter.com/", "_blank")
|
window.open(
|
||||||
|
"https://twitter.com/asimdotshrestha",
|
||||||
|
"_blank"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<FaTwitter size={30} />
|
<FaTwitter size={30} />
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ const Drawer = ({ handleHelp }: { handleHelp: () => void }) => {
|
|||||||
<DrawerItem
|
<DrawerItem
|
||||||
icon={<FaTwitter />}
|
icon={<FaTwitter />}
|
||||||
text="Twitter"
|
text="Twitter"
|
||||||
onClick={() => window.open("https://twitter.com/", "_blank")}
|
onClick={() =>
|
||||||
|
window.open("https://twitter.com/asimdotshrestha", "_blank")
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<DrawerItem
|
<DrawerItem
|
||||||
icon={<FaGithub />}
|
icon={<FaGithub />}
|
||||||
|
|||||||
Reference in New Issue
Block a user