import bookmarks from other platforms + many other improvements

This commit is contained in:
daniel31x13
2023-10-03 14:34:13 +03:30
parent 8fc8874063
commit f15e298cc3
13 changed files with 216 additions and 172 deletions
+9 -8
View File
@@ -5,21 +5,22 @@ const useDetectPageBottom = () => {
useEffect(() => {
const handleScroll = () => {
const offsetHeight = document.documentElement.offsetHeight;
const innerHeight = window.innerHeight;
const scrollTop = document.documentElement.scrollTop;
const totalHeight = document.documentElement.scrollHeight;
const scrolledHeight = window.scrollY + window.innerHeight;
const hasReachedBottom = offsetHeight - (innerHeight + scrollTop) <= 100;
setReachedBottom(hasReachedBottom);
if (scrolledHeight >= totalHeight) {
setReachedBottom(true);
}
};
window.addEventListener("scroll", handleScroll);
return () => window.removeEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
}, []);
return reachedBottom;
return { reachedBottom, setReachedBottom };
};
export default useDetectPageBottom;
+5 -3
View File
@@ -17,7 +17,7 @@ export default function useLinks(
const { links, setLinks, resetLinks } = useLinkStore();
const router = useRouter();
const hasReachedBottom = useDetectPageBottom();
const { reachedBottom, setReachedBottom } = useDetectPageBottom();
const getLinks = async (isInitialCall: boolean, cursor?: number) => {
const requestBody: LinkRequestQuery = {
@@ -48,6 +48,8 @@ export default function useLinks(
}, [router, sort, searchFilter]);
useEffect(() => {
if (hasReachedBottom) getLinks(false, links?.at(-1)?.id);
}, [hasReachedBottom]);
if (reachedBottom) getLinks(false, links?.at(-1)?.id);
setReachedBottom(false);
}, [reachedBottom]);
}