fix(fe/panel_sharings): introduce rows layout in sharing panel

This commit is contained in:
hexxa 2021-12-22 20:42:06 +08:00 committed by Hexxa
parent fc3ecc5543
commit e60804401e
4 changed files with 121 additions and 87 deletions

View file

@ -250,6 +250,14 @@
padding: 1rem 0 1rem 0; 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 { .theme-default #sharing-list .desc {
background-color: #ecf0f1; background-color: #ecf0f1;
font-size: 1.2rem; font-size: 1.2rem;

View file

@ -12,7 +12,7 @@ import { ICoreState, MsgProps, UIProps } from "./core_state";
import { LoginProps } from "./pane_login"; import { LoginProps } from "./pane_login";
import { Flexbox } from "./layout/flexbox"; import { Flexbox } from "./layout/flexbox";
import { Container } from "./layout/container"; import { Container } from "./layout/container";
import { getIcon } from "./visual/icons"; import { Rows, Row } from "./layout/rows";
export interface SharingsProps { export interface SharingsProps {
sharings: List<string>; sharings: List<string>;
@ -35,98 +35,121 @@ export class SharingsPanel extends React.Component<Props, State, {}> {
} }
deleteSharing = async (dirPath: string) => { deleteSharing = async (dirPath: string) => {
return updater() try {
.deleteSharing(dirPath) const deleteStatus = await updater().deleteSharing(dirPath);
.then((status: string) => { if (deleteStatus !== "") {
if (status !== "") { throw deleteStatus;
alertMsg(getErrMsg(this.props.msg.pkg, "op.fail", status)); }
} else { updater().setSharing(false);
updater().setSharing(false);
return this.listSharings(); await this.listSharings();
} } catch (e: any) {
}); alertMsg(getErrMsg(this.props.msg.pkg, "op.fail", status));
}
}; };
listSharings = async () => { listSharings = async () => {
return updater() const status = await updater().listSharings();
.listSharings() if (status !== "") {
.then((status: string) => { alertMsg(getErrMsg(this.props.msg.pkg, "op.fail", status));
if (status !== "") { }
alertMsg(getErrMsg(this.props.msg.pkg, "op.fail", status)); this.props.update(updater().updateFilesInfo);
} this.props.update(updater().updateSharingsInfo);
this.props.update(updater().updateFilesInfo); };
this.props.update(updater().updateSharingsInfo);
}); makeRows = (sharings: List<string>): List<Row> => {
const sharingRows = sharings.map((dirPath: string) => {
const sharingURL = `${
document.location.href.split("?")[0]
}?dir=${encodeURIComponent(dirPath)}`;
const row1 = (
<Flexbox
children={List([
<RiFolderSharedFill
size="3rem"
className="purple0-font margin-r-m"
/>,
<span>{dirPath}</span>,
<button
onClick={() => {
this.deleteSharing(dirPath);
}}
>
{this.props.msg.pkg.get("browser.delete")}
</button>,
])}
childrenStyles={List([
{ flex: "0 0 auto", alignItems: "center" },
{ alignItems: "center", justifyContent: "flex-start" },
{
flex: "0 0 auto",
alignItems: "center",
justifyContent: "flex-end",
},
])}
/>
);
const elem = (
<div className="sharing-item" key={dirPath}>
{row1}
<div className="desc">{sharingURL}</div>
<div className="hr grey0-bg"></div>
</div>
);
return {
elem,
sortVals: List([dirPath]),
val: dirPath,
};
});
return sharingRows;
};
updateSharings = (sharings: List<Object>) => {
const newSharings = sharings as List<string>;
updater().updateSharings(newSharings);
this.props.update(updater().updateSharingsInfo);
}; };
render() { render() {
const nameWidthClass = `item-name item-name-${ const sharingRows = this.makeRows(this.props.sharingsInfo.sharings);
this.props.ui.isVertical ? "vertical" : "horizontal" const view = (
} pointer`; <Rows
rows={sharingRows}
const sharingList = this.props.sharingsInfo.sharings.map( sortKeys={List([this.props.msg.pkg.get("item.path")])}
(dirPath: string) => { updateRows={this.updateSharings}
const sharingURL = `${ />
document.location.href.split("?")[0] );
}?dir=${encodeURIComponent(dirPath)}`; const noSharingView = (
<Container>
return ( <Flexbox
<div className="sharing-item" key={dirPath}> children={List([
<Flexbox <RiEmotionSadLine size="4rem" className="margin-r-m red0-font" />,
children={List([ <span>
<Flexbox <h3 className="title-l">
children={List([ {this.props.msg.pkg.get("share.404.title")}
<RiFolderSharedFill </h3>
size="3rem" <span className="desc-l grey0-font">
className="purple0-font margin-r-m" {this.props.msg.pkg.get("share.404.desc")}
/>, </span>
<span className={nameWidthClass}>{dirPath}</span>, </span>,
])} ])}
/>, childrenStyles={List([
{ flex: "auto", justifyContent: "flex-end" },
<button { flex: "auto" },
onClick={() => { ])}
this.deleteSharing(dirPath); />
}} </Container>
>
{this.props.msg.pkg.get("browser.delete")}
</button>,
])}
childrenStyles={List([
{ alignItems: "center" },
{ alignItems: "center", justifyContent: "flex-end" },
{ alignItems: "center", justifyContent: "flex-end" },
])}
/>
<div className="desc">{sharingURL}</div>
<div className="hr grey0-bg"></div>
</div>
);
}
); );
const list = const list =
this.props.sharingsInfo.sharings.size === 0 ? ( this.props.sharingsInfo.sharings.size === 0 ? (
<Container> noSharingView
<Flexbox
children={List([
<RiEmotionSadLine size="4rem" className="margin-r-m red0-font" />,
<span>
<h3 className="title-l">
{this.props.msg.pkg.get("share.404.title")}
</h3>
<span className="desc-l grey0-font">
{this.props.msg.pkg.get("share.404.desc")}
</span>
</span>,
])}
childrenStyles={List([
{ flex: "auto", justifyContent: "flex-end" },
{ flex: "auto" },
])}
/>
</Container>
) : ( ) : (
<Container> <Container>
<Flexbox <Flexbox
@ -151,9 +174,10 @@ export class SharingsPanel extends React.Component<Props, State, {}> {
<span></span>, <span></span>,
])} ])}
className="margin-b-l"
/> />
{sharingList} {view}
</Container> </Container>
); );

View file

@ -69,8 +69,6 @@ export class UploadingsPanel extends React.Component<Props, State, {}> {
const fileName = pathParts[pathParts.length - 1]; const fileName = pathParts[pathParts.length - 1];
const progress = Math.floor((uploading.uploaded / uploading.size) * 100); const progress = Math.floor((uploading.uploaded / uploading.size) * 100);
// const title = <Flexbox children={List([])} />;
const op = ( const op = (
<div className="item-op"> <div className="item-op">
<button <button
@ -206,7 +204,7 @@ export class UploadingsPanel extends React.Component<Props, State, {}> {
<Container> <Container>
<Flexbox <Flexbox
children={List([ children={List([
<span className="upload-item"> <span className="margin-b-l">
<Flexbox <Flexbox
children={List([ children={List([
<RiUploadCloudFill <RiUploadCloudFill

View file

@ -267,6 +267,10 @@ export class Updater {
this.props.uploadingsInfo.uploadings = uploadings; this.props.uploadingsInfo.uploadings = uploadings;
}; };
updateSharings = (sharings: List<string>) => {
this.props.sharingsInfo.sharings = sharings;
};
moveHere = async ( moveHere = async (
srcDir: string, srcDir: string,
dstDir: string, dstDir: string,