From 807cc21f66c1eecffab6e3bfd72040058d4cc973 Mon Sep 17 00:00:00 2001 From: provefar Date: Tue, 18 Jul 2023 15:34:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=BB=98=E8=AE=A4=E5=85=A8?= =?UTF-8?q?=E9=87=8F=E6=89=B9=E9=87=8F=E4=B8=8B=E8=BD=BD=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E3=80=81=E6=97=A0=E9=80=89=E6=8B=A9=E5=88=99=E7=AD=89=E5=90=8C?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=85=A8=E9=83=A8=20(#159)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add BatchDownloadAll icon to SubActions * feat: Download all when no selected --- .../FileManager/Navigator/SubActions.js | 16 +++++++++++++++- src/redux/explorer/action.ts | 16 +++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/component/FileManager/Navigator/SubActions.js b/src/component/FileManager/Navigator/SubActions.js index 03d6c16..4d648be 100644 --- a/src/component/FileManager/Navigator/SubActions.js +++ b/src/component/FileManager/Navigator/SubActions.js @@ -4,11 +4,12 @@ import ViewListIcon from "@material-ui/icons/ViewList"; import ViewSmallIcon from "@material-ui/icons/ViewComfy"; import ViewModuleIcon from "@material-ui/icons/ViewModule"; import TextTotateVerticalIcon from "@material-ui/icons/TextRotateVertical"; +import DownloadIcon from "@material-ui/icons/CloudDownload"; import Avatar from "@material-ui/core/Avatar"; import { useDispatch, useSelector } from "react-redux"; import Auth from "../../../middleware/Auth"; import { changeViewMethod, setShareUserPopover } from "../../../redux/explorer"; -import { changeSortMethod } from "../../../redux/explorer/action"; +import { changeSortMethod, startBatchDownload } from "../../../redux/explorer/action"; import { FormatPageBreak } from "mdi-material-ui"; import pathHelper from "../../../utils/page"; import { changePageSize } from "../../../redux/viewUpdate/action"; @@ -55,6 +56,10 @@ export default function SubActions({ isSmall, inherit }) { (e) => dispatch(setShareUserPopover(e)), [dispatch] ); + const StartBatchDownloadAll = useCallback( + () => dispatch(startBatchDownload(share)), + [dispatch, share] + ); const ChangePageSize = useCallback((e) => dispatch(changePageSize(e)), [ dispatch, ]); @@ -102,6 +107,15 @@ export default function SubActions({ isSmall, inherit }) { const classes = useStyles(); return ( <> + + + + {viewMethod === "icon" && ( { + const dirs: string[] = [], + items: string[] = []; + const fileSources: CloudreveFile[] = selected.length ? selected : [...dirList, ...fileList]; + fileSources.map((value) => { if (value.type === "dir") { dirs.push(value.id); } else { @@ -246,7 +247,7 @@ export const serverSideBatchDownload = ( }; if (pathHelper.isSharePage(pathname)) { reqURL = "/share/archive/" + share.key; - postBody["path"] = selected[0].path; + postBody["path"] = fileSources[0].path; } API.post(reqURL, postBody) @@ -322,7 +323,7 @@ export const startBatchDownload = ( return async (dispatch, getState): Promise => { dispatch(changeContextMenu("file", false)); const { - explorer: { selected }, + explorer: { selected, fileList, dirList }, } = getState(); const user = Auth.GetUser(); @@ -368,7 +369,8 @@ export const startBatchDownload = ( let queue: CloudreveFile[] = []; try { - queue = await walk(selected, share); + const walkSources = selected.length ? selected : [...dirList, ...fileList]; + queue = await walk(walkSources, share); } catch (e) { dispatch( toggleSnackbar(