import QuickAccess from "../QuickAccess/QuickAccess"; import Folders from "../Folders/Folders"; import { useFiles, useQuickFiles, useUploader } from "../../hooks/files"; import { useInfiniteScroll } from "../../hooks/infiniteScroll"; import Files from "../Files/Files"; import { memo, useCallback, useEffect, useLayoutEffect, useRef, useState, } from "react"; import Spinner from "../Spinner/Spinner"; import { useAppDispatch, useAppSelector } from "../../hooks/store"; import { useLocation, useParams } from "react-router-dom"; import classNames from "classnames"; import { useDragAndDrop, useUtils } from "../../hooks/utils"; import MultiSelectBar from "../MultiSelectBar/MultiSelectBar"; import { useFolder, useFolders } from "../../hooks/folders"; import { removeNavigationMap } from "../../reducers/selected"; import AlertIcon from "../../icons/AlertIcon"; const DataForm = memo( ({ scrollDivRef }: { scrollDivRef: React.RefObject }) => { const { fetchNextPage: filesFetchNextPage, isFetchingNextPage: isFetchingNextPageState, data: fileList, isLoading: isLoadingFiles, } = useFiles(); const { isLoading: isLoadingFolder } = useFolder(true); const { isLoading: isLoadingFolders } = useFolders(); const { isLoading: isLoadingQuickItems } = useQuickFiles(); const dispatch = useAppDispatch(); const { sentinelRef, reachedIntersect } = useInfiniteScroll(); const [initialLoad, setInitialLoad] = useState(true); const params = useParams(); const { uploadFiles } = useUploader(); const isFetchingNextPage = useRef(false); const prevPathname = useRef(""); const location = useLocation(); const navigationMap = useAppSelector((state) => { return state.selected.navigationMap[location.pathname]; }); const { isTrash } = useUtils(); const isLoading = isLoadingFiles || isLoadingFolders || isLoadingQuickItems || isLoadingFolder; useEffect(() => { if (initialLoad) { setInitialLoad(false); return; } else if (!fileList || isFetchingNextPage.current) { return; } if (reachedIntersect && !isLoadingFiles) { isFetchingNextPage.current = true; filesFetchNextPage().then(() => { isFetchingNextPage.current = false; }); } }, [reachedIntersect, initialLoad, isLoadingFiles]); useEffect(() => { if (!isLoading && navigationMap) { const scrollTop = navigationMap.scrollTop; scrollDivRef.current?.scrollTo(0, scrollTop); dispatch(removeNavigationMap(location.pathname)); prevPathname.current = location.pathname; } else if (!isLoading && prevPathname.current !== location.pathname) { scrollDivRef.current?.scrollTo(0, 0); prevPathname.current = location.pathname; } }, [isLoading, navigationMap, location.pathname]); const addFile = useCallback( (files: FileList) => { uploadFiles(files); }, [params.id] ); const { isDraggingFile, onDragDropEvent, onDragEvent, onDragEnterEvent, stopDrag, } = useDragAndDrop(addFile); return (
{!isLoading && (
{isTrash && (
Items in the trash may be automatically deleted depending on the servers settings
)}
)} {isLoading && (
)} {/* @ts-ignore */}
{isFetchingNextPageState && (
)}
); } ); export default DataForm;