From 115f75c5b1f5f69baa499ca7aa09645b0f69264e Mon Sep 17 00:00:00 2001 From: Xuan Son Nguyen Date: Sat, 8 Feb 2025 13:03:33 +0100 Subject: [PATCH] fix auto scroll --- examples/server/webui/src/App.tsx | 15 ++++++++++----- .../webui/src/components/ChatScreen.tsx | 19 +++++++------------ .../webui/src/components/SettingDialog.tsx | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/server/webui/src/App.tsx b/examples/server/webui/src/App.tsx index 5b440bc6d..2ce734682 100644 --- a/examples/server/webui/src/App.tsx +++ b/examples/server/webui/src/App.tsx @@ -27,14 +27,19 @@ function AppLayout() { return ( <> -
+
- { setShowSettings(false)} - />} + { + setShowSettings(false)} + /> + } ); } diff --git a/examples/server/webui/src/components/ChatScreen.tsx b/examples/server/webui/src/components/ChatScreen.tsx index 18f575e19..3c53a82cf 100644 --- a/examples/server/webui/src/components/ChatScreen.tsx +++ b/examples/server/webui/src/components/ChatScreen.tsx @@ -17,22 +17,21 @@ export default function ChatScreen() { canvasData, } = useAppContext(); const [inputMsg, setInputMsg] = useState(''); - const containerRef = useRef(null); const navigate = useNavigate(); const currConvId = viewingConversation?.id ?? ''; const pendingMsg: PendingMessage | undefined = pendingMessages[currConvId]; const scrollToBottom = (requiresNearBottom: boolean) => { - if (!containerRef.current) return; - const msgListElem = containerRef.current; + const mainScrollElem = document.getElementById('main-scroll'); + if (!mainScrollElem) return; const spaceToBottom = - msgListElem.scrollHeight - - msgListElem.scrollTop - - msgListElem.clientHeight; + mainScrollElem.scrollHeight - + mainScrollElem.scrollTop - + mainScrollElem.clientHeight; if (!requiresNearBottom || spaceToBottom < 50) { setTimeout( - () => msgListElem.scrollTo({ top: msgListElem.scrollHeight }), + () => mainScrollElem.scrollTo({ top: mainScrollElem.scrollHeight }), 1 ); } @@ -71,11 +70,7 @@ export default function ChatScreen() { >
{/* chat messages */} -
+
{/* placeholder to shift the message to the bottom */} {viewingConversation ? '' : 'Send a message to start'} diff --git a/examples/server/webui/src/components/SettingDialog.tsx b/examples/server/webui/src/components/SettingDialog.tsx index 679c3a084..592b93fa3 100644 --- a/examples/server/webui/src/components/SettingDialog.tsx +++ b/examples/server/webui/src/components/SettingDialog.tsx @@ -325,7 +325,7 @@ export default function SettingDialog({ }; return ( - +

Settings