11"use client" ;
2-
3- /* eslint-disable no-restricted-syntax */
4- import { ScrollShadow } from "@/components/ui/ScrollShadow/ScrollShadow" ;
52import { useThirdwebClient } from "@/constants/thirdweb.client" ;
63import type { Account } from "@3rdweb-sdk/react/hooks/useApi" ;
74import { useCallback , useEffect , useMemo , useRef , useState } from "react" ;
@@ -111,18 +108,8 @@ export function ChatPageContent(props: {
111108 [ props . type ] ,
112109 ) ;
113110
114- const messagesEndRef = useRef < HTMLDivElement > ( null ) ;
115111 const [ isChatStreaming , setIsChatStreaming ] = useState ( false ) ;
116- const [ isUserSubmittedMessage , setIsUserSubmittedMessage ] = useState ( false ) ;
117-
118- // biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
119- useEffect ( ( ) => {
120- if ( ! isUserSubmittedMessage ) {
121- return ;
122- }
123-
124- messagesEndRef . current ?. scrollIntoView ( { behavior : "smooth" } ) ;
125- } , [ messages , isUserSubmittedMessage ] ) ;
112+ const [ enableAutoScroll , setEnableAutoScroll ] = useState ( false ) ;
126113
127114 const initSession = useCallback ( async ( ) => {
128115 const session = await createSession ( {
@@ -148,7 +135,7 @@ export function ChatPageContent(props: {
148135 ] ) ;
149136
150137 setIsChatStreaming ( true ) ;
151- setIsUserSubmittedMessage ( true ) ;
138+ setEnableAutoScroll ( true ) ;
152139 const abortController = new AbortController ( ) ;
153140
154141 try {
@@ -292,6 +279,7 @@ export function ChatPageContent(props: {
292279 } ) ;
293280 } finally {
294281 setIsChatStreaming ( false ) ;
282+ setEnableAutoScroll ( false ) ;
295283 }
296284 } ,
297285 [
@@ -305,6 +293,8 @@ export function ChatPageContent(props: {
305293 ) ;
306294
307295 const hasDoneAutoPrompt = useRef ( false ) ;
296+
297+ // eslint-disable-next-line no-restricted-syntax
308298 useEffect ( ( ) => {
309299 if (
310300 props . initialPrompt &&
@@ -337,45 +327,40 @@ export function ChatPageContent(props: {
337327 } }
338328 />
339329 </ header >
340- < div className = "container relative flex max-w-[800px] grow flex-col overflow-hidden rounded-lg pb-6" >
330+ < div className = "relative flex grow flex-col overflow-hidden rounded-lg pb-6" >
341331 { showEmptyState ? (
342- < div className = "fade-in-0 flex grow animate-in flex-col justify-center" >
332+ < div className = "fade-in-0 container flex max-w-[800px] grow animate-in flex-col justify-center" >
343333 < EmptyStateChatPageContent sendMessage = { handleSendMessage } />
344334 </ div >
345335 ) : (
346336 < div className = "fade-in-0 relative z-[0] flex max-h-full flex-1 animate-in flex-col overflow-hidden" >
347- < ScrollShadow
348- className = "flex-1"
349- scrollableClassName = "max-h-full"
350- shadowColor = "hsl(var(--background))"
351- shadowClassName = "z-[1]"
352- >
353- < Chats
354- messages = { messages }
355- isChatStreaming = { isChatStreaming }
356- authToken = { props . authToken }
357- sessionId = { sessionId }
358- className = "min-w-0 pt-10 pb-32"
359- twAccount = { props . account }
360- client = { client }
361- />
362- { /* Scroll anchor */ }
363- < div ref = { messagesEndRef } />
364- </ ScrollShadow >
365-
366- < Chatbar
367- sendMessage = { handleSendMessage }
337+ < Chats
338+ messages = { messages }
368339 isChatStreaming = { isChatStreaming }
369- abortChatStream = { ( ) => {
370- chatAbortController ?. abort ( ) ;
371- setChatAbortController ( undefined ) ;
372- setIsChatStreaming ( false ) ;
373- // if last message is presence, remove it
374- if ( messages [ messages . length - 1 ] ?. type === "presence" ) {
375- setMessages ( ( prev ) => prev . slice ( 0 , - 1 ) ) ;
376- }
377- } }
340+ authToken = { props . authToken }
341+ sessionId = { sessionId }
342+ className = "min-w-0 pt-10 pb-32"
343+ twAccount = { props . account }
344+ client = { client }
345+ enableAutoScroll = { enableAutoScroll }
346+ setEnableAutoScroll = { setEnableAutoScroll }
378347 />
348+
349+ < div className = "container max-w-[800px]" >
350+ < Chatbar
351+ sendMessage = { handleSendMessage }
352+ isChatStreaming = { isChatStreaming }
353+ abortChatStream = { ( ) => {
354+ chatAbortController ?. abort ( ) ;
355+ setChatAbortController ( undefined ) ;
356+ setIsChatStreaming ( false ) ;
357+ // if last message is presence, remove it
358+ if ( messages [ messages . length - 1 ] ?. type === "presence" ) {
359+ setMessages ( ( prev ) => prev . slice ( 0 , - 1 ) ) ;
360+ }
361+ } }
362+ />
363+ </ div >
379364 </ div >
380365 ) }
381366
0 commit comments