diff --git a/src/client/web/src/components/panel_uploadings.tsx b/src/client/web/src/components/panel_uploadings.tsx index 7f6cf23..550c57e 100644 --- a/src/client/web/src/components/panel_uploadings.tsx +++ b/src/client/web/src/components/panel_uploadings.tsx @@ -14,12 +14,12 @@ import { LoginProps } from "./pane_login"; import { UploadEntry, UploadState } from "../worker/interface"; import { Flexbox } from "./layout/flexbox"; import { Container } from "./layout/container"; +import { Rows, Row } from "./layout/rows"; export interface UploadingsProps { uploadings: List; uploadFiles: List; } - export interface Props { uploadingsInfo: UploadingsProps; msg: MsgProps; @@ -36,32 +36,26 @@ export class UploadingsPanel extends React.Component { this.state = {}; } - deleteUpload = (filePath: string): Promise => { - return updater() - .deleteUpload(filePath) - .then((status: string) => { - if (status !== "") { - throw status; - } - return updater().refreshUploadings(); - }) - .then((status: string) => { - if (status !== "") { - throw status; - } - return updater().self(); - }) - .then((status: string) => { - if (status !== "") { - throw status; - } + deleteUpload = async (filePath: string): Promise => { + try { + const deleteStatus = await updater().deleteUpload(filePath); + if (deleteStatus !== "") { + throw deleteStatus; + } - this.props.update(updater().updateUploadingsInfo); - this.props.update(updater().updateLogin); - }) - .catch((status: Error) => { - alertMsg(getErrMsg(this.props.msg.pkg, "op.fail", status.toString())); - }); + const statuses = await Promise.all([ + updater().refreshUploadings(), + updater().self(), + ]); + if (statuses.join("") !== "") { + throw statuses.join(";"); + } + + this.props.update(updater().updateLogin); + this.props.update(updater().updateUploadingsInfo); + } catch (status: any) { + alertMsg(getErrMsg(this.props.msg.pkg, "op.fail", status.toString())); + } }; stopUploading = (filePath: string) => { @@ -69,97 +63,145 @@ export class UploadingsPanel extends React.Component { this.props.update(updater().updateUploadingsInfo); }; - render() { - const nameWidthClass = `item-name item-name-${ - this.props.ui.isVertical ? "vertical" : "horizontal" - } pointer`; + makeRowsInputs = (uploadings: List): List => { + const uploadingRows = uploadings.map((uploading: UploadEntry) => { + const pathParts = uploading.filePath.split("/"); + const fileName = pathParts[pathParts.length - 1]; + const progress = Math.floor((uploading.uploaded / uploading.size) * 100); - const uploadingList = this.props.uploadingsInfo.uploadings.map( - (uploading: UploadEntry) => { - const pathParts = uploading.filePath.split("/"); - const fileName = pathParts[pathParts.length - 1]; - const progress = `${Math.floor( - (uploading.uploaded / uploading.size) * 100 - )}%`; - return ( -
- , + // const title = ; -
- {fileName}  - - {FileSize(uploading.uploaded, { round: 0 })} -  /  - {FileSize(uploading.size, { - round: 0, - })} -  /  - {progress} - -
, - ])} - />, + const op = ( +
+ + +
+ ); -
- - -
, - ])} - childrenStyles={List([{}, { justifyContent: "flex-end" }])} - /> -
-
-
- {uploading.err.trim() === "" ? null : ( -
{uploading.err.trim()}
- )} -
+ const progressBar = ( +
+
+
+ ); + + const errorInfo = + uploading.err.trim() === "" ? null : ( +
{uploading.err.trim()}
); - } + + const elem = ( +
+ , + +
+ {fileName}  + + {FileSize(uploading.uploaded, { round: 0 })} +  /  + {FileSize(uploading.size, { + round: 0, + })} +  /  + {`${progress}%`} + +
, + + op, + ])} + childrenStyles={List([ + { flex: "0 0 auto" }, + {}, + { justifyContent: "flex-end" }, + ])} + /> + {progressBar} + {errorInfo} +
+ ); + + // file path, size, progress + const sortVals = List([ + uploading.filePath, + `${uploading.size}`, + `${progress}`, + ]); + return { + elem, + sortVals, + val: uploading, + }; + }); + + return uploadingRows; + }; + + updateUploadings = (uploadings: Object) => { + const newUploadings = uploadings as List; + updater().updateUploadings(newUploadings); + this.props.update(updater().updateUploadingsInfo); + }; + + render() { + const uploadingRows = this.makeRowsInputs( + this.props.uploadingsInfo.uploadings + ); + const sortKeys = List([ + this.props.msg.pkg.get("item.path"), + this.props.msg.pkg.get("item.size"), + this.props.msg.pkg.get("item.progress"), + ]); + const view = ( + + ); + + const noUploadingView = ( + + , + +

+ {this.props.msg.pkg.get("upload.404.title")} +

+ + {this.props.msg.pkg.get("upload.404.desc")} + +
, + ])} + childrenStyles={List([ + { flex: "auto", justifyContent: "flex-end" }, + { flex: "auto" }, + ])} + /> +
); const list = this.props.uploadingsInfo.uploadings.size === 0 ? ( - - , - -

- {this.props.msg.pkg.get("upload.404.title")} -

- - {this.props.msg.pkg.get("upload.404.desc")} - -
, - ])} - childrenStyles={List([ - { flex: "auto", justifyContent: "flex-end" }, - { flex: "auto" }, - ])} - /> -
+ noUploadingView ) : ( { ])} /> - {uploadingList} + {view} ); diff --git a/src/client/web/src/components/state_updater.ts b/src/client/web/src/components/state_updater.ts index f43a8ee..7c4c7f6 100644 --- a/src/client/web/src/components/state_updater.ts +++ b/src/client/web/src/components/state_updater.ts @@ -263,6 +263,10 @@ export class Updater { this.props.filesInfo.items = items; }; + updateUploadings = (uploadings: List) => { + this.props.uploadingsInfo.uploadings = uploadings; + }; + moveHere = async ( srcDir: string, dstDir: string, diff --git a/src/client/web/src/i18n/en_US.ts b/src/client/web/src/i18n/en_US.ts index ecf9f7b..4893143 100644 --- a/src/client/web/src/i18n/en_US.ts +++ b/src/client/web/src/i18n/en_US.ts @@ -125,4 +125,5 @@ export const msgs: Map = Map({ "item.path": "Path", "item.modTime": "Mod Time", "item.size": "Size", + "item.progress": "Progress", }); diff --git a/src/client/web/src/i18n/zh_CN.ts b/src/client/web/src/i18n/zh_CN.ts index 35a2458..9807db3 100644 --- a/src/client/web/src/i18n/zh_CN.ts +++ b/src/client/web/src/i18n/zh_CN.ts @@ -122,4 +122,5 @@ export const msgs: Map = Map({ "item.path": "路径", "item.modTime": "修改时间", "item.size": "大小", + "item.progress": "进度", });