* chore: Add ./components/[name]/index.ts map to package.json * fix: Clarify Popover exports * fix: re-add dropdown to calcom/ui barrel * chore: Add icon barrel file re-export * Fix all calcom/ui imports of its own barrel * Never say 'fix all remaining..' it's never true * Some type fixeS * Linking fixes * Rename sheet.tsx to Sheet.tsx Done through UI, console does NOT like this. * Fixed some test failures
30 lines
887 B
TypeScript
30 lines
887 B
TypeScript
"use client";
|
|
|
|
import { useCallback, useEffect } from "react";
|
|
|
|
export const useFetchMoreOnBottomReached = (
|
|
tableContainerRef: React.RefObject<HTMLDivElement>,
|
|
fetchNextPage: () => void,
|
|
isFetching: boolean,
|
|
totalFetched: number,
|
|
totalDBRowCount: number
|
|
) => {
|
|
const fetchMoreOnBottomReached = useCallback(
|
|
(containerRefElement?: HTMLDivElement | null) => {
|
|
if (containerRefElement) {
|
|
const { scrollHeight, scrollTop, clientHeight } = containerRefElement;
|
|
if (scrollHeight - scrollTop - clientHeight < 300 && !isFetching && totalFetched < totalDBRowCount) {
|
|
fetchNextPage();
|
|
}
|
|
}
|
|
},
|
|
[fetchNextPage, isFetching, totalFetched, totalDBRowCount]
|
|
);
|
|
|
|
useEffect(() => {
|
|
fetchMoreOnBottomReached(tableContainerRef.current);
|
|
}, [fetchMoreOnBottomReached, tableContainerRef]);
|
|
|
|
return fetchMoreOnBottomReached;
|
|
};
|