mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2025-07-02 13:55:43 +00:00
* rework the input area * process selected file * change all icons to heroicons * fix thought process collapse * move conversation more menu to sidebar * sun icon --> moon icon * rm default system message * stricter upload file check, only allow image if server has mtmd * build it * add renaming * better autoscroll * build * add conversation group * fix scroll * extra context first, then user input in the end * fix <hr> tag * clean up a bit * build * add mb-3 for <pre> * throttle adjustTextareaHeight to make it less laggy * (nits) missing padding in sidebar * rm stray console log
35 lines
994 B
TypeScript
35 lines
994 B
TypeScript
import React, { useEffect } from 'react';
|
|
import { throttle } from '../utils/misc';
|
|
|
|
export const scrollToBottom = (requiresNearBottom: boolean, delay?: number) => {
|
|
const mainScrollElem = document.getElementById('main-scroll');
|
|
if (!mainScrollElem) return;
|
|
const spaceToBottom =
|
|
mainScrollElem.scrollHeight -
|
|
mainScrollElem.scrollTop -
|
|
mainScrollElem.clientHeight;
|
|
if (!requiresNearBottom || spaceToBottom < 100) {
|
|
setTimeout(
|
|
() => mainScrollElem.scrollTo({ top: mainScrollElem.scrollHeight }),
|
|
delay ?? 80
|
|
);
|
|
}
|
|
};
|
|
|
|
const scrollToBottomThrottled = throttle(scrollToBottom, 80);
|
|
|
|
export function useChatScroll(msgListRef: React.RefObject<HTMLDivElement>) {
|
|
useEffect(() => {
|
|
if (!msgListRef.current) return;
|
|
|
|
const resizeObserver = new ResizeObserver((_) => {
|
|
scrollToBottomThrottled(true, 10);
|
|
});
|
|
|
|
resizeObserver.observe(msgListRef.current);
|
|
return () => {
|
|
resizeObserver.disconnect();
|
|
};
|
|
}, [msgListRef]);
|
|
}
|