mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 02:10:15 +01:00
📜 refactor: Enhance Auto Scroll Speed and UseEffect Cleanup (#1591)
This commit is contained in:
parent
a7c54573c4
commit
83292a47a7
3 changed files with 10 additions and 4 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import copy from 'copy-to-clipboard';
|
import copy from 'copy-to-clipboard';
|
||||||
import { useEffect, useRef } from 'react';
|
import { useEffect, useRef, useCallback } from 'react';
|
||||||
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
|
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
|
||||||
import type { TMessage } from 'librechat-data-provider';
|
import type { TMessage } from 'librechat-data-provider';
|
||||||
import type { TMessageProps } from '~/common';
|
import type { TMessageProps } from '~/common';
|
||||||
|
|
@ -43,13 +43,13 @@ export default function useMessageHelpers(props: TMessageProps) {
|
||||||
const enterEdit = (cancel?: boolean) =>
|
const enterEdit = (cancel?: boolean) =>
|
||||||
setCurrentEditId && setCurrentEditId(cancel ? -1 : messageId);
|
setCurrentEditId && setCurrentEditId(cancel ? -1 : messageId);
|
||||||
|
|
||||||
const handleScroll = () => {
|
const handleScroll = useCallback(() => {
|
||||||
if (isSubmitting) {
|
if (isSubmitting) {
|
||||||
setAbortScroll(true);
|
setAbortScroll(true);
|
||||||
} else {
|
} else {
|
||||||
setAbortScroll(false);
|
setAbortScroll(false);
|
||||||
}
|
}
|
||||||
};
|
}, [isSubmitting, setAbortScroll]);
|
||||||
|
|
||||||
const icon = Icon({
|
const icon = Icon({
|
||||||
...conversation,
|
...conversation,
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,12 @@ export default function useMessageScrolling(messagesTree?: TMessage[] | null) {
|
||||||
if (isSubmitting && scrollToBottom && !abortScroll) {
|
if (isSubmitting && scrollToBottom && !abortScroll) {
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (abortScroll) {
|
||||||
|
scrollToBottom && scrollToBottom?.cancel();
|
||||||
|
}
|
||||||
|
};
|
||||||
}, [isSubmitting, messagesTree, scrollToBottom, abortScroll]);
|
}, [isSubmitting, messagesTree, scrollToBottom, abortScroll]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ export default function useScrollToRef({ targetRef, callback, smoothCallback }:
|
||||||
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
const scrollToRef = useCallback(
|
const scrollToRef = useCallback(
|
||||||
throttle(() => logAndScroll('instant', callback), 450, { leading: true }),
|
throttle(() => logAndScroll('instant', callback), 250, { leading: true }),
|
||||||
[targetRef],
|
[targetRef],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue