mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-09-20 02:35:45 +08:00
feat: chat panel UE done
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
import { RefObject, useEffect, useState } from "react";
|
||||
import { RefObject, useEffect, useRef, useState } from "react";
|
||||
|
||||
export default function useScrollToBottom(
|
||||
scrollRef: RefObject<HTMLDivElement>,
|
||||
detach: boolean = false,
|
||||
) {
|
||||
// for auto-scroll
|
||||
const detach = scrollRef?.current
|
||||
? Math.abs(
|
||||
scrollRef.current.scrollHeight -
|
||||
(scrollRef.current.scrollTop + scrollRef.current.clientHeight),
|
||||
) <= 1
|
||||
: false;
|
||||
|
||||
const initScrolled = useRef(false);
|
||||
// for auto-scroll
|
||||
const [autoScroll, setAutoScroll] = useState(true);
|
||||
function scrollDomToBottom() {
|
||||
const dom = scrollRef.current;
|
||||
@@ -19,10 +25,11 @@ export default function useScrollToBottom(
|
||||
|
||||
// auto scroll
|
||||
useEffect(() => {
|
||||
if (autoScroll && !detach) {
|
||||
if (autoScroll && !detach && !initScrolled.current) {
|
||||
scrollDomToBottom();
|
||||
initScrolled.current = true;
|
||||
}
|
||||
});
|
||||
}, [autoScroll, detach]);
|
||||
|
||||
return {
|
||||
scrollRef,
|
||||
|
Reference in New Issue
Block a user