Something went wrong. Try again.
Self-hosted file management and sharing system, supports multiple storage providers. forked from tdvorak.tngl.sh/cloudreve
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120import { Box, Stack, useMediaQuery, useTheme } from "@mui/material";import { useEffect } from "react";import { useHotkeys } from "react-hotkeys-hook";import { getAllowedPolicies } from "../../api/api.ts";import useNavigation from "../../hooks/useNavigation.tsx";import { clearSelected } from "../../redux/fileManagerSlice.ts";import { resetDialogs, setPolicyOptionCache } from "../../redux/globalStateSlice.ts";import { useAppDispatch, useAppSelector } from "../../redux/hooks.ts";import { resetFm, selectAll, shortCutDelete } from "../../redux/thunks/filemanager.ts";import SessionManager from "../../session/index.ts";import ImageViewer from "../Viewers/ImageViewer/ImageViewer.tsx";import Explorer from "./Explorer/Explorer.tsx";import { FmIndexContext } from "./FmIndexContext.tsx";import PaginationFooter from "./Pagination/PaginationFooter.tsx";import { ReadMe } from "./ReadMe/ReadMe.tsx";import Sidebar from "./Sidebar/Sidebar.tsx";import SidebarDialog from "./Sidebar/SidebarDialog.tsx";import NavHeader from "./TopBar/NavHeader.tsx";
export const FileManagerIndex = { main: 0, selector: 1,};
export interface FileManagerProps { index?: number; initialPath?: string; skipRender?: boolean;}
export const FileManager = ({ index = 0, initialPath, skipRender }: FileManagerProps) => { const dispatch = useAppDispatch(); const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down("sm")); const isTablet = useMediaQuery(theme.breakpoints.down("md"));
useNavigation(index, initialPath);
const policyCache = useAppSelector((state) => state.globalState.policyOptionCache);
useEffect(() => { if (index == FileManagerIndex.main) { dispatch(resetDialogs()); // Populate the allowed-policy cache for context-menu gating when the // session was restored from storage rather than a fresh login. if (policyCache === undefined && SessionManager.currentLoginOrNull()) { dispatch(getAllowedPolicies()) .then((policies) => dispatch(setPolicyOptionCache(policies))) .catch(() => {}); } return () => { dispatch(resetFm(index)); }; } }, []);
const selectAllRef = useHotkeys<HTMLElement>( ["Control+a", "Meta+a"], () => { dispatch(selectAll(index)); }, { enabled: index == FileManagerIndex.main, preventDefault: true }, );
const delRef = useHotkeys<HTMLElement>( ["meta+backspace", "delete"], () => { dispatch(shortCutDelete(index)); }, { enabled: index == FileManagerIndex.main, preventDefault: true }, );
const escRef = useHotkeys<HTMLElement>( "esc", () => { dispatch(clearSelected({ index, value: {} })); }, { enabled: index == FileManagerIndex.main, preventDefault: true }, );
if (skipRender) { return null; }
return ( <FmIndexContext.Provider value={index}> <Stack onClick={(e) => { e.currentTarget.focus(); }} ref={(ref) => { selectAllRef(ref); delRef(ref); escRef(ref); }} direction={"column"} sx={{ flexGrow: 1, mb: index == FileManagerIndex.main && !isMobile ? 1 : 0, overflow: "auto", "&:focus": { outline: "none", }, }} tabIndex={0} spacing={1} > <NavHeader /> <Box sx={{ display: "flex", flexGrow: 1, overflowY: "auto" }}> <Explorer /> {index == FileManagerIndex.main && (isTablet ? <SidebarDialog /> : <Sidebar />)} {index == FileManagerIndex.main && <ReadMe />} </Box> <PaginationFooter /> </Stack> {index == FileManagerIndex.main && <ImageViewer />} </FmIndexContext.Provider> );};