diff --git a/client/src/components/MessageWrapper.tsx b/client/src/components/MessageWrapper.tsx index c36cccf..7b9fef9 100644 --- a/client/src/components/MessageWrapper.tsx +++ b/client/src/components/MessageWrapper.tsx @@ -21,7 +21,7 @@ const MessageWrapper = () => { return (
- + {isLoading ? '' : isError diff --git a/client/src/components/ScrollToBottom.tsx b/client/src/components/ScrollToBottom.tsx index 60bb13d..ee50abd 100644 --- a/client/src/components/ScrollToBottom.tsx +++ b/client/src/components/ScrollToBottom.tsx @@ -4,24 +4,29 @@ import { FaChevronDown } from 'react-icons/fa'; const ScrollToBottom = ({ children, className = '' }: { children: ReactNode; className?: string }) => { const [node, setNode] = useState(null); const [show, setShow] = useState(false); - + const bottom = useCallback((node: HTMLDivElement) => { if (node) { node.scrollIntoView({ behavior: 'smooth' }); setNode(node); } }, []); - + useEffect(() => { - document.querySelector('main > div')?.addEventListener('scroll', () => { + const container = document.querySelector('main > div'); + container?.addEventListener('scroll', () => { if (node?.getBoundingClientRect() && node.getBoundingClientRect().y >= window.innerHeight) { setShow(true); } else { setShow(false); } }); + container?.addEventListener('DOMNodeInserted', () => { + if (node?.getBoundingClientRect() && node.getBoundingClientRect().y >= window.innerHeight) { + node?.scrollIntoView({ behavior: 'smooth' }); + } + }); }, [node]); - return ( <> @@ -31,11 +36,11 @@ const ScrollToBottom = ({ children, className = '' }: { children: ReactNode; cla );