ScrollTopButton: fix autoloading timelines

sw-index-revalidate
Alex Gleason 2022-06-28 19:23:25 -05:00
rodzic adf4789317
commit 0afa42502f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 14 dodań i 4 usunięć

Wyświetl plik

@ -34,14 +34,20 @@ const ScrollTopButton: React.FC<IScrollTopButton> = ({
const [scrolled, setScrolled] = useState<boolean>(false);
const autoload = settings.get('autoloadTimelines') === true;
const handleScroll = useCallback(throttle(() => {
const { scrollTop } = (document.scrollingElement || document.documentElement);
const getScrollTop = (): number => {
return (document.scrollingElement || document.documentElement).scrollTop;
};
if (autoload && scrollTop <= autoloadThreshold) {
const maybeUnload = () => {
if (autoload && getScrollTop() <= autoloadThreshold) {
onClick();
}
};
if (scrollTop > threshold) {
const handleScroll = useCallback(throttle(() => {
maybeUnload();
if (getScrollTop() > threshold) {
setScrolled(true);
} else {
setScrolled(false);
@ -65,6 +71,10 @@ const ScrollTopButton: React.FC<IScrollTopButton> = ({
};
}, []);
useEffect(() => {
maybeUnload();
}, [count]);
const visible = count > 0 && scrolled;
const classes = classNames('left-1/2 -translate-x-1/2 fixed top-20 z-50', {