From 688de9106b3e1b127f76da6307b607ad8665fe6a Mon Sep 17 00:00:00 2001 From: TatianaLopaeva Date: Fri, 18 Jun 2021 10:58:01 +0300 Subject: [PATCH] Web: Files: SelectFileDialog: Added infinity scroll for files list. --- .../panels/SelectFileDialog/fileListBody.js | 133 +++++++++++++++--- 1 file changed, 113 insertions(+), 20 deletions(-) diff --git a/products/ASC.Files/Client/src/components/panels/SelectFileDialog/fileListBody.js b/products/ASC.Files/Client/src/components/panels/SelectFileDialog/fileListBody.js index 3e3d2cfe8c..cdf1e258cf 100644 --- a/products/ASC.Files/Client/src/components/panels/SelectFileDialog/fileListBody.js +++ b/products/ASC.Files/Client/src/components/panels/SelectFileDialog/fileListBody.js @@ -1,30 +1,119 @@ -import React from "react"; +import React, { useCallback } from "react"; import Loader from "@appserver/components/loader"; import Text from "@appserver/components/text"; import { useTranslation } from "react-i18next"; -const FileListBody = ({ isLoadingData, filesList, onFileClick }) => { - const { t } = useTranslation(["SelectFile", "Common"]); +import { ReactSVG } from "react-svg"; +import config from "../../../../package.json"; +import Checkbox from "@appserver/components/checkbox"; +import CustomScrollbarsVirtualList from "@appserver/components/scrollbar/custom-scrollbars-virtual-list"; +import InfiniteLoader from "react-window-infinite-loader"; +import AutoSizer from "react-virtualized-auto-sizer"; +import { FixedSizeList as List } from "react-window"; - return ( - <> - {!isLoadingData ? ( - filesList.length > 0 ? ( - filesList.map((data, index) => ( -
-
- {data.title.substring(0, data.title.indexOf(".gz"))} +const FileListBody = ({ + isLoadingData, + filesList, + onSelectFile, + isModalView, + loadNextPage, + hasNextPage, + isNextPageLoading, +}) => { + const { t } = useTranslation(["SelectFile", "Common"]); + // Every row is loaded except for our loading indicator row. + const isItemLoaded = useCallback( + (index) => { + return !hasNextPage || index < filesList.length; + }, + [hasNextPage, filesList] + ); + // If there are more items to be loaded then add an extra row to hold a loading indicator. + const itemCount = hasNextPage ? filesList.length + 1 : filesList.length; + + const loadMoreItems = useCallback( + (startIndex) => { + if (isNextPageLoading) return; + console.log("startIndex", startIndex); + const options = { + startIndex: startIndex || 0, + }; + + loadNextPage && loadNextPage(options); + }, + [isNextPageLoading, filesList] + ); + + const Item = useCallback( + ({ index, style }) => { + return ( +
+ {!isItemLoaded(index) ? ( +
+ + {`${t("Common:LoadingProcessing")} ${t( + "Common:LoadingDescription" + )}`} +
+ ) : ( +
+ +
+ {filesList[index] && + filesList[index].title.substring( + 0, + filesList[index].title.indexOf(".gz") + )}
{".gz"}
- )) - ) : ( - {`${t("Home:EmptyFolderHeader")}`} - ) + )} +
+ ); + }, + [filesList] + ); + return ( + <> + {!isLoadingData ? ( + + {({ width }) => ( + + {({ onItemsRendered, ref }) => ( + + {Item} + + )} + + )} + ) : (
@@ -36,4 +125,8 @@ const FileListBody = ({ isLoadingData, filesList, onFileClick }) => { ); }; +FileListBody.defaultProps = { + isModalView: false, + isLoadingData: false, +}; export default FileListBody;