Skip to content

Commit

Permalink
📜 refactor: Enhance Auto Scroll Speed and UseEffect Cleanup (danny-av…
Browse files Browse the repository at this point in the history
  • Loading branch information
danny-avila authored Jan 19, 2024
1 parent dac7989 commit a55414b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions client/src/hooks/Messages/useMessageHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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 type { TMessage } from 'librechat-data-provider';
import type { TMessageProps } from '~/common';
Expand Down Expand Up @@ -43,13 +43,13 @@ export default function useMessageHelpers(props: TMessageProps) {
const enterEdit = (cancel?: boolean) =>
setCurrentEditId && setCurrentEditId(cancel ? -1 : messageId);

const handleScroll = () => {
const handleScroll = useCallback(() => {
if (isSubmitting) {
setAbortScroll(true);
} else {
setAbortScroll(false);
}
};
}, [isSubmitting, setAbortScroll]);

const icon = Icon({
...conversation,
Expand Down
6 changes: 6 additions & 0 deletions client/src/hooks/Messages/useMessageScrolling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export default function useMessageScrolling(messagesTree?: TMessage[] | null) {
if (isSubmitting && scrollToBottom && !abortScroll) {
scrollToBottom();
}

return () => {
if (abortScroll) {
scrollToBottom && scrollToBottom?.cancel();
}
};
}, [isSubmitting, messagesTree, scrollToBottom, abortScroll]);

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion client/src/hooks/useScrollToRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function useScrollToRef({ targetRef, callback, smoothCallback }:

// eslint-disable-next-line react-hooks/exhaustive-deps
const scrollToRef = useCallback(
throttle(() => logAndScroll('instant', callback), 450, { leading: true }),
throttle(() => logAndScroll('instant', callback), 250, { leading: true }),
[targetRef],
);

Expand Down

0 comments on commit a55414b

Please sign in to comment.