Skip to content

Commit 115f75c

Browse files
committed
fix auto scroll
1 parent 483a3bc commit 115f75c

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

examples/server/webui/src/App.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,19 @@ function AppLayout() {
2727
return (
2828
<>
2929
<Sidebar />
30-
<div className="drawer-content grow flex flex-col h-screen w-screen mx-auto px-4 overflow-auto">
30+
<div
31+
className="drawer-content grow flex flex-col h-screen w-screen mx-auto px-4 overflow-auto"
32+
id="main-scroll"
33+
>
3134
<Header />
3235
<Outlet />
3336
</div>
34-
{<SettingDialog
35-
show={showSettings}
36-
onClose={() => setShowSettings(false)}
37-
/>}
37+
{
38+
<SettingDialog
39+
show={showSettings}
40+
onClose={() => setShowSettings(false)}
41+
/>
42+
}
3843
</>
3944
);
4045
}

examples/server/webui/src/components/ChatScreen.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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'}

examples/server/webui/src/components/SettingDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export default function SettingDialog({
325325
};
326326

327327
return (
328-
<dialog className={classNames({ 'modal': true, 'modal-open': show })}>
328+
<dialog className={classNames({ modal: true, 'modal-open': show })}>
329329
<div className="modal-box w-11/12 max-w-3xl">
330330
<h3 className="text-lg font-bold mb-6">Settings</h3>
331331
<div className="flex flex-col md:flex-row h-[calc(90vh-12rem)]">

0 commit comments

Comments
 (0)