@@ -17,22 +17,21 @@ export default function ChatScreen() {
1717 canvasData,
1818 } = useAppContext ( ) ;
1919 const [ inputMsg , setInputMsg ] = useState ( '' ) ;
20- const containerRef = useRef < HTMLDivElement > ( null ) ;
2120 const navigate = useNavigate ( ) ;
2221
2322 const currConvId = viewingConversation ?. id ?? '' ;
2423 const pendingMsg : PendingMessage | undefined = pendingMessages [ currConvId ] ;
2524
2625 const scrollToBottom = ( requiresNearBottom : boolean ) => {
27- if ( ! containerRef . current ) return ;
28- const msgListElem = containerRef . current ;
26+ const mainScrollElem = document . getElementById ( 'main-scroll' ) ;
27+ if ( ! mainScrollElem ) return ;
2928 const spaceToBottom =
30- msgListElem . scrollHeight -
31- msgListElem . scrollTop -
32- msgListElem . clientHeight ;
29+ mainScrollElem . scrollHeight -
30+ mainScrollElem . scrollTop -
31+ mainScrollElem . clientHeight ;
3332 if ( ! requiresNearBottom || spaceToBottom < 50 ) {
3433 setTimeout (
35- ( ) => msgListElem . scrollTo ( { top : msgListElem . scrollHeight } ) ,
34+ ( ) => mainScrollElem . scrollTo ( { top : mainScrollElem . scrollHeight } ) ,
3635 1
3736 ) ;
3837 }
@@ -71,11 +70,7 @@ export default function ChatScreen() {
7170 >
7271 < div className = "flex flex-col w-full max-w-[900px] mx-auto" >
7372 { /* chat messages */ }
74- < div
75- id = "messages-list"
76- className = "flex flex-col grow overflow-y-auto"
77- ref = { containerRef }
78- >
73+ < div id = "messages-list" className = "flex flex-col grow overflow-y-auto" >
7974 < div className = "mt-auto flex justify-center" >
8075 { /* placeholder to shift the message to the bottom */ }
8176 { viewingConversation ? '' : 'Send a message to start' }
0 commit comments