fastapi-rtk
Version:
A React component library for FastAPI in combination with FastAPI React Toolkit backend, built with Mantine, JsonForms, and Zustand.
34 lines (33 loc) • 1.35 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const utils = require("fastapi-rtk/utils");
const core = require("@mantine/core");
const hooks = require("@mantine/hooks");
const React = require("react");
const useApi = require("../../hooks/api/useApi.cjs");
const InfiniteScroll = ({
children,
fetch = true,
components: {
Loading = /* @__PURE__ */ jsxRuntime.jsx(core.Center, { children: /* @__PURE__ */ jsxRuntime.jsx(core.Loader, {}) }),
End = /* @__PURE__ */ jsxRuntime.jsx(core.Center, { children: "End of data" }),
FetchWrapper = core.Center
} = {},
fetchWrapperProps
}) => {
const { streaming, loading } = useApi.useApi();
const { ref, inViewport } = hooks.useInViewport();
const items = React.useMemo(() => Object.values(streaming.data).flat(), [streaming.data]);
React.useEffect(() => {
if (inViewport && fetch) {
streaming.fetch();
}
}, [fetch, inViewport]);
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
utils.parseFromValuesOrFunc(children, { items, loading }),
streaming.isEnd && End,
loading ? Loading : /* @__PURE__ */ jsxRuntime.jsx(FetchWrapper, { ref, id: "IS-load-trigger", mih: "1%", ...fetchWrapperProps })
] });
};
exports.InfiniteScroll = InfiniteScroll;
;