Skip to content

Commit 2d2b8de

Browse files
committed
fix scroll
1 parent 47e7314 commit 2d2b8de

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

tools/server/public/index.html.gz

330 Bytes
Binary file not shown.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,8 @@ export default function ChatScreen() {
239239
''
240240
) : (
241241
<>
242+
<div className="mb-4">Send a message to start</div>
242243
<ServerInfo />
243-
<br />
244-
Send a message to start
245244
</>
246245
)}
247246
</div>

tools/server/webui/src/components/useChatScroll.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
import React, { useEffect } from 'react';
22
import { throttle } from '../utils/misc';
33

4-
export const scrollToBottom = throttle(
5-
(requiresNearBottom: boolean, delay?: number) => {
6-
const mainScrollElem = document.getElementById('main-scroll');
7-
if (!mainScrollElem) return;
8-
const spaceToBottom =
9-
mainScrollElem.scrollHeight -
10-
mainScrollElem.scrollTop -
11-
mainScrollElem.clientHeight;
12-
if (!requiresNearBottom || spaceToBottom < 100) {
13-
setTimeout(
14-
() => mainScrollElem.scrollTo({ top: mainScrollElem.scrollHeight }),
15-
delay ?? 80
16-
);
17-
}
18-
},
19-
80
20-
);
4+
export const scrollToBottom = (requiresNearBottom: boolean, delay?: number) => {
5+
console.log({ requiresNearBottom });
6+
const mainScrollElem = document.getElementById('main-scroll');
7+
if (!mainScrollElem) return;
8+
const spaceToBottom =
9+
mainScrollElem.scrollHeight -
10+
mainScrollElem.scrollTop -
11+
mainScrollElem.clientHeight;
12+
if (!requiresNearBottom || spaceToBottom < 100) {
13+
setTimeout(
14+
() => mainScrollElem.scrollTo({ top: mainScrollElem.scrollHeight }),
15+
delay ?? 80
16+
);
17+
}
18+
};
19+
20+
const scrollToBottomThrottled = throttle(scrollToBottom, 80);
2121

2222
export function useChatScroll(msgListRef: React.RefObject<HTMLDivElement>) {
2323
useEffect(() => {
2424
if (!msgListRef.current) return;
2525

2626
const resizeObserver = new ResizeObserver((_) => {
27-
scrollToBottom(true);
27+
scrollToBottomThrottled(true, 10);
2828
});
2929

3030
resizeObserver.observe(msgListRef.current);

0 commit comments

Comments
 (0)