From e60804401e2475c67bc9efccd2ca3df5f93c4cab Mon Sep 17 00:00:00 2001 From: hexxa Date: Wed, 22 Dec 2021 20:42:06 +0800 Subject: [PATCH] fix(fe/panel_sharings): introduce rows layout in sharing panel --- public/static/css/white.css | 8 + .../web/src/components/panel_sharings.tsx | 192 ++++++++++-------- .../web/src/components/panel_uploadings.tsx | 4 +- .../web/src/components/state_updater.ts | 4 + 4 files changed, 121 insertions(+), 87 deletions(-) diff --git a/public/static/css/white.css b/public/static/css/white.css index 19bd901..f4c260a 100644 --- a/public/static/css/white.css +++ b/public/static/css/white.css @@ -250,6 +250,14 @@ padding: 1rem 0 1rem 0; } +.theme-default .upload-item .error { + font-size: 1.4rem; + padding: 1rem; + color: #f1c40f; + margin: 1rem 0 0 0; + background-color: #2c3e50; +} + .theme-default #sharing-list .desc { background-color: #ecf0f1; font-size: 1.2rem; diff --git a/src/client/web/src/components/panel_sharings.tsx b/src/client/web/src/components/panel_sharings.tsx index 5b90b74..603b501 100644 --- a/src/client/web/src/components/panel_sharings.tsx +++ b/src/client/web/src/components/panel_sharings.tsx @@ -12,7 +12,7 @@ import { ICoreState, MsgProps, UIProps } from "./core_state"; import { LoginProps } from "./pane_login"; import { Flexbox } from "./layout/flexbox"; import { Container } from "./layout/container"; -import { getIcon } from "./visual/icons"; +import { Rows, Row } from "./layout/rows"; export interface SharingsProps { sharings: List; @@ -35,98 +35,121 @@ export class SharingsPanel extends React.Component { } deleteSharing = async (dirPath: string) => { - return updater() - .deleteSharing(dirPath) - .then((status: string) => { - if (status !== "") { - alertMsg(getErrMsg(this.props.msg.pkg, "op.fail", status)); - } else { - updater().setSharing(false); - return this.listSharings(); - } - }); + try { + const deleteStatus = await updater().deleteSharing(dirPath); + if (deleteStatus !== "") { + throw deleteStatus; + } + updater().setSharing(false); + + await this.listSharings(); + } catch (e: any) { + alertMsg(getErrMsg(this.props.msg.pkg, "op.fail", status)); + } }; listSharings = async () => { - return updater() - .listSharings() - .then((status: string) => { - if (status !== "") { - alertMsg(getErrMsg(this.props.msg.pkg, "op.fail", status)); - } - this.props.update(updater().updateFilesInfo); - this.props.update(updater().updateSharingsInfo); - }); + const status = await updater().listSharings(); + if (status !== "") { + alertMsg(getErrMsg(this.props.msg.pkg, "op.fail", status)); + } + this.props.update(updater().updateFilesInfo); + this.props.update(updater().updateSharingsInfo); + }; + + makeRows = (sharings: List): List => { + const sharingRows = sharings.map((dirPath: string) => { + const sharingURL = `${ + document.location.href.split("?")[0] + }?dir=${encodeURIComponent(dirPath)}`; + + const row1 = ( + , + {dirPath}, + + , + ])} + childrenStyles={List([ + { flex: "0 0 auto", alignItems: "center" }, + { alignItems: "center", justifyContent: "flex-start" }, + { + flex: "0 0 auto", + alignItems: "center", + justifyContent: "flex-end", + }, + ])} + /> + ); + + const elem = ( +
+ {row1} +
{sharingURL}
+
+
+ ); + + return { + elem, + sortVals: List([dirPath]), + val: dirPath, + }; + }); + + return sharingRows; + }; + + updateSharings = (sharings: List) => { + const newSharings = sharings as List; + updater().updateSharings(newSharings); + this.props.update(updater().updateSharingsInfo); }; render() { - const nameWidthClass = `item-name item-name-${ - this.props.ui.isVertical ? "vertical" : "horizontal" - } pointer`; - - const sharingList = this.props.sharingsInfo.sharings.map( - (dirPath: string) => { - const sharingURL = `${ - document.location.href.split("?")[0] - }?dir=${encodeURIComponent(dirPath)}`; - - return ( -
- , - {dirPath}, - ])} - />, - - , - ])} - childrenStyles={List([ - { alignItems: "center" }, - { alignItems: "center", justifyContent: "flex-end" }, - { alignItems: "center", justifyContent: "flex-end" }, - ])} - /> - -
{sharingURL}
-
-
- ); - } + const sharingRows = this.makeRows(this.props.sharingsInfo.sharings); + const view = ( + + ); + const noSharingView = ( + + , + +

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

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

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

- - {this.props.msg.pkg.get("share.404.desc")} - -
, - ])} - childrenStyles={List([ - { flex: "auto", justifyContent: "flex-end" }, - { flex: "auto" }, - ])} - /> -
+ noSharingView ) : ( { , ])} + className="margin-b-l" /> - {sharingList} + {view} ); diff --git a/src/client/web/src/components/panel_uploadings.tsx b/src/client/web/src/components/panel_uploadings.tsx index 550c57e..10f64a2 100644 --- a/src/client/web/src/components/panel_uploadings.tsx +++ b/src/client/web/src/components/panel_uploadings.tsx @@ -69,8 +69,6 @@ export class UploadingsPanel extends React.Component { const fileName = pathParts[pathParts.length - 1]; const progress = Math.floor((uploading.uploaded / uploading.size) * 100); - // const title = ; - const op = (