2022-08-09 10:43:24 +00:00
|
|
|
import React, { useRef } from "react";
|
2022-07-11 14:06:21 +00:00
|
|
|
import PropTypes from "prop-types";
|
2022-08-09 10:43:24 +00:00
|
|
|
import { WindowScroller } from "react-virtualized";
|
2022-08-10 10:27:52 +00:00
|
|
|
import { isMobileOnly } from "react-device-detect";
|
2022-07-15 08:58:58 +00:00
|
|
|
import ListComponent from "./List";
|
|
|
|
import GridComponent from "./Grid";
|
|
|
|
|
2022-08-09 10:43:24 +00:00
|
|
|
const InfiniteLoaderComponent = (props) => {
|
|
|
|
const ref = useRef(null);
|
|
|
|
|
2022-08-10 10:27:52 +00:00
|
|
|
const scroll = isMobileOnly
|
|
|
|
? document.querySelector("#customScrollBar > .scroll-body")
|
|
|
|
: document.querySelector("#sectionScroll > .scroll-body");
|
2022-08-09 10:43:24 +00:00
|
|
|
|
|
|
|
const onScroll = ({ scrollTop }) => {
|
|
|
|
ref.current.scrollTo(scrollTop);
|
|
|
|
};
|
2022-07-11 14:06:21 +00:00
|
|
|
|
2022-08-09 10:43:24 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<WindowScroller scrollElement={scroll} onScroll={onScroll}>
|
|
|
|
{() => <div />}
|
|
|
|
</WindowScroller>
|
|
|
|
|
|
|
|
{props.viewAs === "tile" ? (
|
|
|
|
<GridComponent listRef={ref} {...props} />
|
|
|
|
) : (
|
|
|
|
<ListComponent listRef={ref} {...props} />
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2022-07-11 14:06:21 +00:00
|
|
|
InfiniteLoaderComponent.propTypes = {
|
|
|
|
viewAs: PropTypes.string.isRequired,
|
|
|
|
hasMoreFiles: PropTypes.bool.isRequired,
|
|
|
|
filesLength: PropTypes.number.isRequired,
|
|
|
|
itemCount: PropTypes.number.isRequired,
|
|
|
|
loadMoreItems: PropTypes.func.isRequired,
|
2022-07-15 08:58:58 +00:00
|
|
|
itemSize: PropTypes.number,
|
2022-07-11 14:06:21 +00:00
|
|
|
children: PropTypes.any.isRequired,
|
|
|
|
/** Called when the list scroll positions changes */
|
|
|
|
onScroll: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default InfiniteLoaderComponent;
|