fix(fe): hide elements in sharing mode

This commit is contained in:
hexxa 2021-09-25 18:48:03 +08:00 committed by Hexxa
parent 08ed7f175b
commit 1f5dd061d6
7 changed files with 158 additions and 137 deletions

View file

@ -15,7 +15,7 @@ import { alertMsg, comfirmMsg } from "../common/env";
import { updater } from "./state_updater"; import { updater } from "./state_updater";
import { ICoreState, MsgProps } from "./core_state"; import { ICoreState, MsgProps } from "./core_state";
import { LoginProps } from "./pane_login"; import { LoginProps } from "./pane_login";
import { MetadataResp, UploadInfo } from "../client"; import { MetadataResp, roleVisitor } from "../client";
import { Up } from "../worker/upload_mgr"; import { Up } from "../worker/upload_mgr";
import { UploadEntry } from "../worker/interface"; import { UploadEntry } from "../worker/interface";
import { Flexbox } from "./layout/flexbox"; import { Flexbox } from "./layout/flexbox";
@ -316,6 +316,8 @@ export class Browser extends React.Component<Props, State, {}> {
}; };
render() { render() {
const showOp = this.props.login.userRole === roleVisitor ? "hidden" : "";
let breadcrumb = this.props.browser.dirPath.map( let breadcrumb = this.props.browser.dirPath.map(
(pathPart: string, key: number) => { (pathPart: string, key: number) => {
return ( return (
@ -422,7 +424,7 @@ export class Browser extends React.Component<Props, State, {}> {
/> />
</span>, </span>,
<span className="padding-m"> <span className={`padding-m ${showOp}`}>
<button <button
onClick={() => this.select(item.name)} onClick={() => this.select(item.name)}
className={`${isSelected ? "blue0-bg white-font" : "grey2-bg grey3-font" className={`${isSelected ? "blue0-bg white-font" : "grey2-bg grey3-font"
@ -438,10 +440,9 @@ export class Browser extends React.Component<Props, State, {}> {
childrenStyles={List([{}, { justifyContent: "flex-end" }])} childrenStyles={List([{}, { justifyContent: "flex-end" }])}
/> />
) : ( ) : (
<div> <div key={item.name}>
<Flexbox <Flexbox
key={item.name}
children={List([ children={List([
<span className="padding-m"> <span className="padding-m">
<Flexbox <Flexbox
@ -468,7 +469,7 @@ export class Browser extends React.Component<Props, State, {}> {
/> />
</span>, </span>,
<span className="item-op padding-m"> <span className={`item-op padding-m ${showOp}`}>
<button <button
type="button" type="button"
onClick={() => this.select(item.name)} onClick={() => this.select(item.name)}
@ -506,14 +507,16 @@ export class Browser extends React.Component<Props, State, {}> {
round: 0, round: 0,
} }
); );
const itemListPane = const itemListPane =
this.props.browser.tab === "" || this.props.browser.tab === "item" ? ( this.props.browser.tab === "" || this.props.browser.tab === "item" ? (
<div> <div>
<div id="op-bar" className="op-bar"> <div id="op-bar" className={`op-bar ${showOp}`}>
<div className="margin-l-m margin-r-m margin-b-m">{ops}</div> <div className="margin-l-m margin-r-m margin-b-m">{ops}</div>
</div> </div>
<div className="container"> <div className="container">
<div className={`${showOp}`} >
<Flexbox <Flexbox
children={List([ children={List([
<span> <span>
@ -569,6 +572,7 @@ export class Browser extends React.Component<Props, State, {}> {
className="padding-m" className="padding-m"
childrenStyles={List([{}, { justifyContent: "flex-end" }])} childrenStyles={List([{}, { justifyContent: "flex-end" }])}
/> />
</div>
<Flexbox <Flexbox
children={List([ children={List([
@ -585,7 +589,7 @@ export class Browser extends React.Component<Props, State, {}> {
/> />
</span>, </span>,
<span className="padding-m"> <span className={`padding-m ${showOp}`}>
<button <button
onClick={() => this.selectAll()} onClick={() => this.selectAll()}
className={`grey1-bg white-font`} className={`grey1-bg white-font`}
@ -721,9 +725,8 @@ export class Browser extends React.Component<Props, State, {}> {
const sharingList = this.props.browser.sharings.map((dirPath: string) => { const sharingList = this.props.browser.sharings.map((dirPath: string) => {
return ( return (
<div className="padding-m"> <div key={dirPath} className="padding-m">
<Flexbox <Flexbox
key={dirPath}
children={List([ children={List([
<Flexbox <Flexbox
children={List([ children={List([
@ -818,10 +821,11 @@ export class Browser extends React.Component<Props, State, {}> {
) )
) : null; ) : null;
const showTabs = this.props.login.userRole === roleVisitor ? "hidden" : "";
return ( return (
<div> <div>
<div id="item-list"> <div id="item-list">
<div className="container"> <div className={`container ${showTabs}`}>
<div className="padding-m"> <div className="padding-m">
<button <button
onClick={() => { onClick={() => {
@ -880,8 +884,12 @@ export class Browser extends React.Component<Props, State, {}> {
</button> </button>
</div> </div>
</div> </div>
<div>
{sharingListPane} {sharingListPane}
</div>
<div>
{uploadingListPane} {uploadingListPane}
</div>
{itemListPane} {itemListPane}
</div> </div>
</div> </div>

View file

@ -1,4 +1,5 @@
import * as React from "react"; import * as React from "react";
import { Set } from "immutable";
import { ICoreState, MsgProps } from "./core_state"; import { ICoreState, MsgProps } from "./core_state";
import { updater } from "./state_updater"; import { updater } from "./state_updater";
@ -61,39 +62,22 @@ export class AuthPane extends React.Component<Props, State, {}> {
) )
.then((ok: boolean): Promise<any> => { .then((ok: boolean): Promise<any> => {
if (ok) { if (ok) {
this.update(updater().updateLogin); const params = new URLSearchParams(document.location.search.substring(1));
this.setState({ user: "", pwd: "", captchaInput: "" }); return updater().initAll(params);
// close all the panes
updater().displayPane("");
this.update(updater().updatePanes);
// refresh
return Promise.all([
updater().setHomeItems(),
updater().refreshUploadings(),
updater().isSharing(updater().props.browser.dirPath.join("/")),
updater().listSharings(),
updater().self(),
]);
} else { } else {
this.setState({ user: "", pwd: "", captchaInput: "" }); this.setState({ user: "", pwd: "", captchaInput: "" });
alertMsg("Failed to login."); alertMsg("Failed to login.");
return updater().getCaptchaID(); return updater().getCaptchaID();
} }
}) })
.then(() => { .then(() => {
this.update(updater().updateBrowser); this.update(updater().updateBrowser);
this.update(updater().updateLogin); this.update(updater().updateLogin);
this.update(updater().updatePanes);
this.update(updater().updateAdmin);
updater().initLan(); updater().initLan();
this.update(updater().updateMsg); this.update(updater().updateMsg);
})
.then(() => {
return updater().isSharing(updater().props.browser.dirPath.join("/"));
})
.then(() => {
this.update(updater().updateBrowser);
}); });
}; };

View file

@ -55,6 +55,7 @@ export class Panes extends React.Component<Props, State, {}> {
{this.props.msg.pkg.get("panes.close")} {this.props.msg.pkg.get("panes.close")}
</button> </button>
</div> </div>
</div> </div>
</div> </div>

View file

@ -6,6 +6,8 @@ import { LoginProps } from "./pane_login";
import { Panes, PanesProps } from "./panes"; import { Panes, PanesProps } from "./panes";
import { AdminProps } from "./pane_admin"; import { AdminProps } from "./pane_admin";
import { TopBar } from "./topbar"; import { TopBar } from "./topbar";
import { roleVisitor } from "../client";
export interface Props { export interface Props {
browser: BrowserProps; browser: BrowserProps;
@ -31,6 +33,8 @@ export class RootFrame extends React.Component<Props, State, {}> {
} }
: {}; : {};
const showBrowser = this.props.login.userRole === roleVisitor && !this.props.browser.isSharing ? "hidden" : "";
return ( return (
<div className="theme-white desktop"> <div className="theme-white desktop">
<div id="bg" className="bg bg-img font-m" style={wallpaperStyle}> <div id="bg" className="bg bg-img font-m" style={wallpaperStyle}>
@ -49,7 +53,7 @@ export class RootFrame extends React.Component<Props, State, {}> {
update={this.props.update} update={this.props.update}
/> />
<div className="container-center"> <div className={`container-center ${showBrowser}`}>
<Browser <Browser
browser={this.props.browser} browser={this.props.browser}
msg={this.props.msg} msg={this.props.msg}

View file

@ -41,58 +41,7 @@ export class StateMgr extends React.Component<Props, State, {}> {
const params = new URLSearchParams(document.location.search.substring(1)); const params = new URLSearchParams(document.location.search.substring(1));
return updater() return updater()
.initIsAuthed() .initAll(params)
.then(() => {
return updater().self();
})
.then(() => {
const dir = params.get("dir");
if (dir != null && dir !== "") {
const dirPath = List(dir.split("/"));
return updater().setItems(dirPath);
} else {
return updater().setHomeItems();
}
})
.then(() => {
return updater().isSharing(updater().props.browser.dirPath.join("/"));
})
.then(() => {
// init browser content
if (updater().props.login.userRole === roleVisitor) {
if (updater().props.browser.isSharing) {
// sharing with visitor
updater().setPanes(Set<string>(["login"]));
updater().displayPane("");
return Promise.all([]);
}
// redirect to login
updater().setPanes(Set<string>(["login"]));
updater().displayPane("login");
return Promise.all([updater().getCaptchaID()]);
}
if (updater().props.login.userRole === roleAdmin) {
updater().setPanes(Set<string>(["login", "settings", "admin"]));
} else {
updater().setPanes(Set<string>(["login", "settings"]));
}
updater().displayPane("");
return Promise.all([
updater().refreshUploadings(),
updater().initUploads(),
updater().listSharings(),
]);
})
.then(() => {
// init admin content
if (updater().props.login.userRole === roleAdmin) {
return Promise.all([updater().listRoles(), updater().listUsers()]);
}
return;
})
.then(() => { .then(() => {
this.update(updater().updateBrowser); this.update(updater().updateBrowser);
this.update(updater().updateLogin); this.update(updater().updateLogin);

View file

@ -13,6 +13,7 @@ import {
Quota, Quota,
Response, Response,
roleVisitor, roleVisitor,
roleAdmin,
} from "../client"; } from "../client";
import { FilesClient } from "../client/files"; import { FilesClient } from "../client/files";
import { UsersClient } from "../client/users"; import { UsersClient } from "../client/users";
@ -210,6 +211,8 @@ export class Updater {
this.props.browser.items = List<MetadataResp>(listResp.data.metadatas); this.props.browser.items = List<MetadataResp>(listResp.data.metadatas);
return true; return true;
} }
this.props.browser.dirPath = List<string>([]);
this.props.browser.items = List<MetadataResp>([]);
return false; return false;
}; };
@ -221,6 +224,8 @@ export class Updater {
this.props.browser.items = List<MetadataResp>(listResp.data.metadatas); this.props.browser.items = List<MetadataResp>(listResp.data.metadatas);
return true; return true;
} }
this.props.browser.dirPath = List<string>([]);
this.props.browser.items = List<MetadataResp>([]);
return false; return false;
}; };
@ -289,6 +294,66 @@ export class Updater {
this.props.panes.paneNames = paneNames; this.props.panes.paneNames = paneNames;
}; };
initPanes = async (): Promise<Array<any>> => {
// init browser content
if (this.props.login.userRole === roleVisitor) {
if (this.props.browser.isSharing) {
// sharing with visitor
this.setPanes(Set<string>(["login"]));
this.displayPane("");
return Promise.all([]);
}
// redirect to login
this.setPanes(Set<string>(["login"]));
this.displayPane("login");
return Promise.all([this.getCaptchaID()]);
}
if (this.props.login.userRole === roleAdmin) {
this.setPanes(Set<string>(["login", "settings", "admin"]));
} else {
this.setPanes(Set<string>(["login", "settings"]));
}
this.displayPane("");
return Promise.all([
this.refreshUploadings(),
this.initUploads(),
this.listSharings(),
]);
};
initAll = async (params: URLSearchParams): Promise<any> => {
return this.initIsAuthed()
.then(() => {
return this.self();
})
.then(() => {
const dir = params.get("dir");
if (dir != null && dir !== "") {
const dirPath = List(dir.split("/"));
return this.setItems(dirPath);
} else {
return this.setHomeItems();
}
})
.then(() => {
return this.isSharing(this.props.browser.dirPath.join("/"));
})
.then(() => {
// init panes
return this.initPanes();
})
.then(() => {
// init admin content
if (this.props.login.userRole === roleAdmin) {
return Promise.all([this.listRoles(), this.listUsers()]);
}
return;
})
};
self = async (): Promise<boolean> => { self = async (): Promise<boolean> => {
const resp = await this.usersClient.self(); const resp = await this.usersClient.self();
if (resp.status === 200) { if (resp.status === 200) {

View file

@ -1,5 +1,5 @@
import * as React from "react"; import * as React from "react";
import { List } from "immutable"; import { List, Set } from "immutable";
import { alertMsg } from "../common/env"; import { alertMsg } from "../common/env";
import { ICoreState, MsgProps } from "./core_state"; import { ICoreState, MsgProps } from "./core_state";
@ -42,18 +42,28 @@ export class TopBar extends React.Component<Props, State, {}> {
}); });
}; };
logout = async () => { logout = async (): Promise<void> => {
return updater() return updater()
.logout() .logout()
.then((ok: boolean) => { .then((ok: boolean) => {
if (ok) { if (ok) {
this.props.update(updater().updateLogin); const params = new URLSearchParams(document.location.search.substring(1));
return updater().initAll(params);
} else { } else {
alertMsg(this.props.msg.pkg.get("login.logout.fail")); alertMsg(this.props.msg.pkg.get("login.logout.fail"));
} }
}) })
.then(() => { .then(() => {
return this.refreshCaptcha(); return this.refreshCaptcha();
})
.then(() => {
this.props.update(updater().updateBrowser);
this.props.update(updater().updateLogin);
this.props.update(updater().updatePanes);
this.props.update(updater().updateAdmin);
updater().initLan();
this.props.update(updater().updateMsg);
}); });
}; };