fix: throttle scroll to bottom

This commit is contained in:
Daniel Avila 2023-03-19 11:45:03 -04:00
parent 4ce60537ca
commit 4cd0ff2682
2 changed files with 4 additions and 3 deletions

View file

@ -49,7 +49,6 @@ const inLineWrap = (parts) => {
export default function TextWrapper({ text, generateCursor }) { export default function TextWrapper({ text, generateCursor }) {
let embedTest = false; let embedTest = false;
let result = null; let result = null;
console.log('text wrapper', text)
// to match unenclosed code blocks // to match unenclosed code blocks
if (text.match(/```/g)?.length === 1) { if (text.match(/```/g)?.length === 1) {

View file

@ -1,5 +1,6 @@
import React, { useEffect, useState, useRef, useCallback } from 'react'; import React, { useEffect, useState, useRef, useCallback } from 'react';
import Spinner from '../svg/Spinner'; import Spinner from '../svg/Spinner';
import { throttle } from 'lodash';
import { CSSTransition } from 'react-transition-group'; import { CSSTransition } from 'react-transition-group';
import ScrollToBottom from './ScrollToBottom'; import ScrollToBottom from './ScrollToBottom';
import MultiMessage from './MultiMessage'; import MultiMessage from './MultiMessage';
@ -34,10 +35,11 @@ export default function Messages({ messages, messageTree }) {
}; };
}, [messages]); }, [messages]);
const scrollToBottom = useCallback(() => { const scrollToBottom = useCallback(throttle(() => {
console.log('scrollToBottom');
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
setShowScrollButton(false); setShowScrollButton(false);
}, [messagesEndRef]); }, 750), [messagesEndRef]);
const handleScroll = () => { const handleScroll = () => {
const { scrollTop, scrollHeight, clientHeight } = scrollableRef.current; const { scrollTop, scrollHeight, clientHeight } = scrollableRef.current;