import { CircularProgress, Grid, Paper, Table, TableBody, TableCell, TableHead, TableRow, Typography, } from "@material-ui/core"; import TableSortLabel from "@material-ui/core/TableSortLabel"; import classNames from "classnames"; import React, { useCallback, useEffect, useMemo } from "react"; import { configure, GlobalHotKeys } from "react-hotkeys"; import explorer, { changeContextMenu, openRemoveDialog, setSelectedTarget } from "../../redux/explorer"; import { isMac } from "../../utils"; import pathHelper from "../../utils/page"; import ContextMenu from "./ContextMenu"; import ImgPreivew from "./ImgPreview"; import ObjectIcon from "./ObjectIcon"; import Nothing from "../Placeholder/Nothing"; import { useDispatch, useSelector } from "react-redux"; import { useLocation } from "react-router"; import { usePagination } from "../../hooks/pagination"; import { makeStyles } from "@material-ui/core/styles"; const useStyles = makeStyles((theme) => ({ paper: { padding: theme.spacing(2), textAlign: "center", color: theme.palette.text.secondary, margin: "10px", }, root: { padding: "10px", }, rootTable: { padding: "0px", backgroundColor: theme.palette.background.paper.white, }, typeHeader: { margin: "10px 25px", color: "#6b6b6b", fontWeight: "500", }, loading: { justifyContent: "center", display: "flex", marginTop: "40px", }, errorBox: { padding: theme.spacing(4), }, errorMsg: { marginTop: "10px", }, hideAuto: { [theme.breakpoints.down("sm")]: { display: "none", }, }, flexFix: { minWidth: 0, }, upButton: { marginLeft: "20px", marginTop: "10px", marginBottom: "10px", }, clickAway: { height: "100%", width: "100%", }, rootShare: {}, visuallyHidden: { border: 0, clip: "rect(0 0 0 0)", height: 1, margin: -1, overflow: "hidden", padding: 0, position: "absolute", top: 20, width: 1, }, gridContainer: { [theme.breakpoints.down("sm")]: { gridTemplateColumns: "repeat(auto-fill,minmax(180px,1fr))!important", }, [theme.breakpoints.up("md")]: { gridTemplateColumns: "repeat(auto-fill,minmax(220px,1fr))!important", }, display: "grid!important", }, gridItem: { flex: "1 1 220px!important", }, })); const keyMap = { DELETE_FILE: "del", SELECT_ALL_SHOWED: `${isMac() ? "command" : "ctrl"}+a`, SELECT_ALL: `${isMac() ? "command" : "ctrl"}+shift+a`, DESELECT_ALL: "esc", }; export default function Explorer({ share }) { const location = useLocation(); const dispatch = useDispatch(); const selected = useSelector((state) => state.explorer.selected); const search = useSelector((state) => state.explorer.search); const loading = useSelector((state) => state.viewUpdate.navigatorLoading); const path = useSelector((state) => state.navigator.path); const sortMethod = useSelector((state) => state.viewUpdate.sortMethod); const navigatorErrorMsg = useSelector( (state) => state.viewUpdate.navigatorErrorMsg ); const navigatorError = useSelector( (state) => state.viewUpdate.navigatorError ); const viewMethod = useSelector( (state) => state.viewUpdate.explorerViewMethod ); const OpenRemoveDialog = useCallback(() => dispatch(openRemoveDialog()), [ dispatch, ]); const SetSelectedTarget = useCallback( (targets) => dispatch(setSelectedTarget(targets)), [dispatch] ); const ChangeContextMenu = useCallback( (type, open) => dispatch(changeContextMenu(type, open)), [dispatch] ); const ChangeSortMethod = useCallback( (method) => dispatch(explorer.actions.changeSortMethod(method)), [dispatch] ); const SelectAll = useCallback( () => dispatch(explorer.actions.selectAll()), [dispatch] ); const { dirList, fileList, startIndex } = usePagination(); const handlers = { DELETE_FILE: () => { if (selected.length > 0 && !share) { OpenRemoveDialog(); } }, SELECT_ALL_SHOWED: (e) => { e.preventDefault(); if (selected.length >= dirList.length + fileList.length) { SetSelectedTarget([]); } else { SetSelectedTarget([...dirList, ...fileList]); } }, SELECT_ALL: (e) => { e.preventDefault(); SelectAll(); }, DESELECT_ALL: (e) => { e.preventDefault(); SetSelectedTarget([]); }, }; useEffect( () => configure({ ignoreTags: ["input", "select", "textarea"], }), [] ); const contextMenu = (e) => { e.preventDefault(); if (!search && !pathHelper.isSharePage(location.pathname)) { if (!loading) { ChangeContextMenu("empty", true); } } }; const ClickAway = (e) => { const element = e.target; if (element.dataset.clickaway) { SetSelectedTarget([]); } }; const classes = useStyles(); const isHomePage = pathHelper.isHomePage(location.pathname); const showView = !loading && (dirList.length !== 0 || fileList.length !== 0); const listView = useMemo( () => (