From 22744e2f2fef68cd5fdc3fee198edbffc8e848b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD-=E7=99=BD?= Date: Thu, 7 Jul 2022 20:21:28 +0800 Subject: [PATCH] enhance remote download dashboard (#119) * fix: aria2 task page navigation * feat: improve performance with virtual list * feat: hide remote download when disabled * Update aria2 file list style --- src/component/Download/DownloadingCard.js | 321 +++++++++++++--------- src/component/Download/FinishedCard.js | 167 ++++++----- src/component/Modals/SelectFile.js | 18 +- src/component/Navbar/Navbar.js | 32 ++- 4 files changed, 323 insertions(+), 215 deletions(-) diff --git a/src/component/Download/DownloadingCard.js b/src/component/Download/DownloadingCard.js index d8f0a31..750a71c 100644 --- a/src/component/Download/DownloadingCard.js +++ b/src/component/Download/DownloadingCard.js @@ -19,13 +19,13 @@ import Grid from "@material-ui/core/Grid"; import withStyles from "@material-ui/core/styles/withStyles"; import Table from "@material-ui/core/Table"; import TableBody from "@material-ui/core/TableBody"; -import TableCell from "@material-ui/core/TableCell"; import TableRow from "@material-ui/core/TableRow"; +import TableCell from "@material-ui/core/TableCell"; import Tooltip from "@material-ui/core/Tooltip"; import { ExpandMore, HighlightOff } from "@material-ui/icons"; import PermMediaIcon from "@material-ui/icons/PermMedia"; import classNames from "classnames"; -import React, { useCallback, useEffect } from "react"; +import React, { useCallback, useEffect, useMemo } from "react"; import { useDispatch } from "react-redux"; import TimeAgo from "timeago-react"; import { toggleSnackbar } from "../../redux/explorer"; @@ -34,7 +34,9 @@ import { hex2bin, sizeToString } from "../../utils"; import TypeIcon from "../FileManager/TypeIcon"; import SelectFileDialog from "../Modals/SelectFile"; import { useHistory } from "react-router"; +import { TableVirtuoso } from "react-virtuoso"; import { useTranslation } from "react-i18next"; + const ExpansionPanel = withStyles({ root: { maxWidth: "100%", @@ -123,14 +125,26 @@ const useStyles = makeStyles((theme) => ({ expanded: { transform: "rotate(180deg)", }, + subFile: { + width: "100%", + minWidth: 300, + wordBreak: "break-all", + }, subFileName: { display: "flex", }, subFileIcon: { marginRight: "20px", }, + subFileSize: { + minWidth: 120, + }, + subFilePercent: { + minWidth: 105, + }, scroll: { - overflowY: "auto", + overflow: "auto", + maxHeight: "300px", }, action: { padding: theme.spacing(2), @@ -325,6 +339,177 @@ export default function DownloadingCard(props) { }); }; + const subFileList = useMemo(() => { + const processStyle = (value) => ({ + background: + "linear-gradient(to right, " + + (theme.palette.type === + "dark" + ? darken( + theme.palette + .primary + .main, + 0.4 + ) + : lighten( + theme.palette + .primary + .main, + 0.85 + )) + + " 0%," + + (theme.palette.type === + "dark" + ? darken( + theme.palette + .primary + .main, + 0.4 + ) + : lighten( + theme.palette + .primary + .main, + 0.85 + )) + + " " + + getPercent( + value.completedLength, + value.length + ).toFixed(0) + + "%," + + theme.palette.background + .paper + + " " + + getPercent( + value.completedLength, + value.length + ).toFixed(0) + + "%," + + theme.palette.background + .paper + + " 100%)", + }); + + const subFileCell = (value) => ( + <> + + + + {value.path} + + + + + {" "} + {sizeToString( + value.length + )} + + + + + {getPercent( + value.completedLength, + value.length + ).toFixed(2)} + % + + + + + + deleteFile( + value.index + ) + } + disabled={loading} + size={"small"} + > + + + + + + ); + + return activeFiles().length > 5 ? ( + , + // eslint-disable-next-line react/display-name + TableRow: (props) => { + const index = props["data-index"]; + const value = activeFiles()[index]; + return ( + + ); + }, + }} + data={activeFiles()} + itemContent={(index, value) => ( + subFileCell(value) + )} + /> + ) : ( +
+
+ + {activeFiles().map((value) => { + return ( + + {subFileCell(value)} + + ); + })} + +
+ + ); + }, [ + classes, + theme, + activeFiles, + ]); + return ( - {task.info.bittorrent.mode === "multi" && ( -
- - - {activeFiles().map((value) => { - return ( - - - - - {value.path} - - - - - {" "} - {sizeToString( - value.length - )} - - - - - {getPercent( - value.completedLength, - value.length - ).toFixed(2)} - % - - - - - - deleteFile( - value.index - ) - } - disabled={loading} - size={"small"} - > - - - - - - ); - })} - -
-
- )} - + {task.info.bittorrent.mode === "multi" && subFileList}
+ ); + }, [ + classes, + activeFiles, + ]); + return ( - {props.task.files.length > 1 && ( -
- - - {activeFiles().map((value) => { - return ( - - - - - {value.path} - - - - - {" "} - {sizeToString( - value.length - )} - - - - - {getPercent( - value.completedLength, - value.length - ).toFixed(2)} - % - - - - ); - })} - -
-
- )} - + {props.task.files.length > 1 && subFileList}