@@ -8,7 +8,7 @@ import { ChatInput } from "@/components/ui/chat/chat-input";
8
8
import { ChatMessageList } from "@/components/ui/chat/chat-message-list" ;
9
9
import { useTransition , animated , type AnimatedProps } from "@react-spring/web" ;
10
10
import { Paperclip , Send , X } from "lucide-react" ;
11
- import { useEffect , useRef , useState , useCallback } from "react" ;
11
+ import { useEffect , useRef , useState } from "react" ;
12
12
import type { Content , UUID } from "@elizaos/core" ;
13
13
import { useMutation , useQueryClient } from "@tanstack/react-query" ;
14
14
import { apiClient } from "@/lib/api" ;
@@ -22,6 +22,7 @@ import AIWriter from "react-aiwriter";
22
22
import type { IAttachment } from "@/types" ;
23
23
import { AudioRecorder } from "./audio-recorder" ;
24
24
import { Badge } from "./ui/badge" ;
25
+ import { useAutoScroll } from "./ui/chat/hooks/useAutoScroll" ;
25
26
26
27
type ExtraContentFields = {
27
28
user : string ;
@@ -39,7 +40,6 @@ export default function Page({ agentId }: { agentId: UUID }) {
39
40
const { toast } = useToast ( ) ;
40
41
const [ selectedFile , setSelectedFile ] = useState < File | null > ( null ) ;
41
42
const [ input , setInput ] = useState ( "" ) ;
42
- const messagesContainerRef = useRef < HTMLDivElement > ( null ) ;
43
43
const inputRef = useRef < HTMLTextAreaElement > ( null ) ;
44
44
const fileInputRef = useRef < HTMLInputElement > ( null ) ;
45
45
const formRef = useRef < HTMLFormElement > ( null ) ;
@@ -49,13 +49,10 @@ export default function Page({ agentId }: { agentId: UUID }) {
49
49
const getMessageVariant = ( role : string ) =>
50
50
role !== "user" ? "received" : "sent" ;
51
51
52
- const scrollToBottom = useCallback ( ( ) => {
53
- if ( messagesContainerRef . current ) {
54
- messagesContainerRef . current . scrollTop =
55
- messagesContainerRef . current . scrollHeight ;
56
- }
57
- } , [ ] ) ;
58
-
52
+ const { scrollRef, isAtBottom, scrollToBottom, disableAutoScroll } = useAutoScroll ( {
53
+ smooth : true ,
54
+ } ) ;
55
+
59
56
useEffect ( ( ) => {
60
57
scrollToBottom ( ) ;
61
58
} , [ queryClient . getQueryData ( [ "messages" , agentId ] ) ] ) ;
@@ -176,7 +173,12 @@ export default function Page({ agentId }: { agentId: UUID }) {
176
173
return (
177
174
< div className = "flex flex-col w-full h-[calc(100dvh)] p-4" >
178
175
< div className = "flex-1 overflow-y-auto" >
179
- < ChatMessageList ref = { messagesContainerRef } >
176
+ < ChatMessageList
177
+ scrollRef = { scrollRef }
178
+ isAtBottom = { isAtBottom }
179
+ scrollToBottom = { scrollToBottom }
180
+ disableAutoScroll = { disableAutoScroll }
181
+ >
180
182
{ transitions ( ( style , message : ContentWithUser ) => {
181
183
const variant = getMessageVariant ( message ?. user ) ;
182
184
return (
0 commit comments