diff --git a/client/src/components/ScrollToBottom.tsx b/client/src/components/ScrollToBottom.tsx index 8e5f138..60bb13d 100644 --- a/client/src/components/ScrollToBottom.tsx +++ b/client/src/components/ScrollToBottom.tsx @@ -1,12 +1,27 @@ -import { ReactNode, useCallback, useState } from 'react'; +import { ReactNode, useCallback, useEffect, useState } from 'react'; 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', () => { + if (node?.getBoundingClientRect() && node.getBoundingClientRect().y >= window.innerHeight) { + setShow(true); + } else { + setShow(false); + } + }); + }, [node]); + return ( <> @@ -16,7 +31,7 @@ const ScrollToBottom = ({ children, className = '' }: { children: ReactNode; cla