next-data-kit 7.6.4 → 7.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1818,7 +1818,11 @@ var DataKitInfinityInner = (props, ref) => {
1818
1818
  }, {})
1819
1819
  }
1820
1820
  });
1821
- const { ref: loadMoreRef, inView } = useInView({
1821
+ const { ref: loadMoreBottomRef, inView: inViewBottom } = useInView({
1822
+ threshold: 0,
1823
+ rootMargin: "100px"
1824
+ });
1825
+ const { ref: loadMoreTopRef, inView: inViewTop } = useInView({
1822
1826
  threshold: 0,
1823
1827
  rootMargin: "100px"
1824
1828
  });
@@ -1900,26 +1904,15 @@ var DataKitInfinityInner = (props, ref) => {
1900
1904
  }
1901
1905
  }, [dataKit.items, dataKit.page, inverse]);
1902
1906
  useEffect(() => {
1903
- if (inView && !inverse) {
1907
+ if (inViewBottom && !inverse) {
1904
1908
  loadMore();
1905
1909
  }
1906
- }, [inView, inverse, loadMore]);
1910
+ }, [inViewBottom, inverse, loadMore]);
1907
1911
  useEffect(() => {
1908
- if (!inverse) return;
1909
- const handleScroll = () => {
1910
- const container2 = scrollContainerRef.current;
1911
- if (!container2) return;
1912
- if (container2.scrollTop === 0 && !dataKit.state.isLoading && dataKit.state.hasNextPage) {
1913
- loadMore();
1914
- }
1915
- };
1916
- const container = scrollContainerRef.current;
1917
- if (container) {
1918
- container.addEventListener("scroll", handleScroll);
1919
- return () => container.removeEventListener("scroll", handleScroll);
1912
+ if (inViewTop && inverse) {
1913
+ loadMore();
1920
1914
  }
1921
- return void 0;
1922
- }, [inverse, loadMore, dataKit.state.isLoading, dataKit.state.hasNextPage]);
1915
+ }, [inViewTop, inverse, loadMore]);
1923
1916
  const enhancedDataKit = {
1924
1917
  ...dataKit,
1925
1918
  items: allItems
@@ -1996,12 +1989,12 @@ var DataKitInfinityInner = (props, ref) => {
1996
1989
  }
1997
1990
  ),
1998
1991
  !manual && isPullRefreshing && /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ jsx(Loader2, { className: "size-6 animate-spin text-muted-foreground" }) }),
1999
- !manual && inverse && dataKit.state.hasNextPage && dataKit.state.isLoading && /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ jsx(Loader2, { className: "size-6 animate-spin text-muted-foreground" }) }),
1992
+ inverse && /* @__PURE__ */ jsx("div", { ref: loadMoreTopRef, className: manual ? "" : "flex items-center justify-center py-4", children: !manual && dataKit.state.hasNextPage && dataKit.state.isLoading && /* @__PURE__ */ jsx(Loader2, { className: "size-6 animate-spin text-muted-foreground" }) }),
2000
1993
  manual ? children(enhancedDataKit) : /* @__PURE__ */ jsxs(Fragment, { children: [
2001
1994
  children(enhancedDataKit),
2002
1995
  !dataKit.state.isLoading && allItems.length === 0 && /* @__PURE__ */ jsx("div", { className: "flex h-48 items-center justify-center text-muted-foreground", children: "No results found." })
2003
1996
  ] }),
2004
- !inverse && /* @__PURE__ */ jsx("div", { ref: loadMoreRef, className: manual ? "" : "flex items-center justify-center py-4", children: !manual && /* @__PURE__ */ jsxs(Fragment, { children: [
1997
+ !inverse && /* @__PURE__ */ jsx("div", { ref: loadMoreBottomRef, className: manual ? "" : "flex items-center justify-center py-4", children: !manual && /* @__PURE__ */ jsxs(Fragment, { children: [
2005
1998
  dataKit.state.isLoading && /* @__PURE__ */ jsx(Loader2, { className: "size-6 animate-spin text-muted-foreground" }),
2006
1999
  !dataKit.state.isLoading && !dataKit.state.hasNextPage && allItems.length > 0 && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "You're all set" })
2007
2000
  ] }) })