From 916ec7c2dcf6081f10cc77cb0dcd36b0b5af1c47 Mon Sep 17 00:00:00 2001 From: Hexxa Date: Sun, 25 Jul 2021 03:19:57 -0500 Subject: [PATCH] fix(ui): fix layout of list & pane (#66) * fix(ui): refine pane layout * fix(test): add pane_admin component --- public/static/css/reset.css | 11 -- public/static/css/style.css | 8 +- src/client/web/src/client/index.ts | 7 + src/client/web/src/components/core_state.ts | 12 +- src/client/web/src/components/pane_admin.tsx | 178 ++++++++++++++++++ src/client/web/src/components/pane_login.tsx | 15 +- .../web/src/components/pane_settings.tsx | 61 +++++- src/client/web/src/components/panes.tsx | 45 +++-- src/client/web/src/components/root_frame.tsx | 2 + src/client/web/src/components/state_mgr.tsx | 1 + 10 files changed, 294 insertions(+), 46 deletions(-) create mode 100644 src/client/web/src/components/pane_admin.tsx diff --git a/public/static/css/reset.css b/public/static/css/reset.css index fe46807..9bd5121 100644 --- a/public/static/css/reset.css +++ b/public/static/css/reset.css @@ -73,17 +73,6 @@ img { max-width: 100%; } -p, -h1, -h2, -h3, -h4, -h5, -h6 { - text-align: left; - padding: 1rem 0; -} - table { border-collapse: collapse; border-spacing: 0; diff --git a/public/static/css/style.css b/public/static/css/style.css index 0e5c21f..0d2d583 100644 --- a/public/static/css/style.css +++ b/public/static/css/style.css @@ -53,7 +53,7 @@ .container-center { margin: 2rem auto auto auto; width: 96%; - max-width: 800px; + max-width: 80rem; z-index: 9; } @@ -75,7 +75,7 @@ } #panes .container { - max-width: 960px; + max-width: 80rem; width: 96%; background-color: white; z-index: 101; @@ -629,4 +629,8 @@ div.hr { .breadcrumb { font-size: 1.4rem; +} + +.txt-cap { + text-transform: capitalize; } \ No newline at end of file diff --git a/src/client/web/src/client/index.ts b/src/client/web/src/client/index.ts index dc5609f..c80214a 100644 --- a/src/client/web/src/client/index.ts +++ b/src/client/web/src/client/index.ts @@ -2,6 +2,13 @@ import axios, { AxiosRequestConfig } from "axios"; export const defaultTimeout = 10000; +export interface User { + ID: string; + Name: string; + Pwd: string; + Role: string; +} + export interface MetadataResp { name: string; size: number; diff --git a/src/client/web/src/components/core_state.ts b/src/client/web/src/components/core_state.ts index c7470c2..7abc5f1 100644 --- a/src/client/web/src/components/core_state.ts +++ b/src/client/web/src/components/core_state.ts @@ -1,11 +1,11 @@ -import { List, Set } from "immutable"; +import { List, Set, Map } from "immutable"; import BgWorker from "../worker/upload.bg.worker"; import { FgWorker } from "../worker/upload.fgworker"; import { Props as PanelProps } from "./root_frame"; import { Item } from "./browser"; -import { UploadInfo } from "../client"; +import { UploadInfo, User } from "../client"; import { Up, initUploadMgr, IWorker } from "../worker/upload_mgr"; export class BaseUpdater { @@ -66,6 +66,10 @@ export function initState(): ICoreState { authed: false, }, }, + admin: { + users: Map(), + roles: Set() + } }, }; } @@ -94,6 +98,10 @@ export function mockState(): ICoreState { authed: false, }, }, + admin: { + users: Map(), + roles: Set() + } }, }; } diff --git a/src/client/web/src/components/pane_admin.tsx b/src/client/web/src/components/pane_admin.tsx new file mode 100644 index 0000000..116c98b --- /dev/null +++ b/src/client/web/src/components/pane_admin.tsx @@ -0,0 +1,178 @@ +import * as React from "react"; +import { Map, Set } from "immutable"; + +import { ICoreState } from "./core_state"; +import { IUsersClient, User} from "../client"; +import { UsersClient } from "../client/users"; +import { Updater as PanesUpdater } from "./panes"; +import { updater as BrowserUpdater } from "./browser.updater"; +import { Layouter } from "./layouter"; + +export interface Props { + users: Map; + roles: Set; + update?: (updater: (prevState: ICoreState) => ICoreState) => void; +} + +export class Updater { + private static props: Props; + private static client: IUsersClient; + + static init = (props: Props) => (Updater.props = { ...props }); + + static setClient = (client: IUsersClient): void => { + Updater.client = client; + }; + + // static adduser = async (user: User): Promise => { + // const resp = await Updater.client.add + // } + + // static login = async (user: string, pwd: string): Promise => { + // const resp = await Updater.client.login(user, pwd); + // Updater.setAuthed(resp.status === 200); + // return resp.status === 200; + // }; + + // static logout = async (): Promise => { + // const resp = await Updater.client.logout(); + // Updater.setAuthed(false); + // return resp.status === 200; + // }; + + // static isAuthed = async (): Promise => { + // const resp = await Updater.client.isAuthed(); + // return resp.status === 200; + // }; + + // static initIsAuthed = async (): Promise => { + // return Updater.isAuthed().then((isAuthed) => { + // Updater.setAuthed(isAuthed); + // }); + // }; + + static setState = (preState: ICoreState): ICoreState => { + preState.panel.authPane = { + ...preState.panel.authPane, + ...Updater.props, + }; + return preState; + }; +} + +// export interface State { +// user: string; +// pwd: string; +// } + +// export class AuthPane extends React.Component { +// private update: (updater: (prevState: ICoreState) => ICoreState) => void; +// constructor(p: Props) { +// super(p); +// Updater.init(p); +// Updater.setClient(new UsersClient("")); +// this.update = p.update; +// this.state = { +// user: "", +// pwd: "", +// }; + +// this.initIsAuthed(); +// } + +// changeUser = (ev: React.ChangeEvent) => { +// this.setState({ user: ev.target.value }); +// }; + +// changePwd = (ev: React.ChangeEvent) => { +// this.setState({ pwd: ev.target.value }); +// }; + +// initIsAuthed = () => { +// Updater.initIsAuthed().then(() => { +// this.update(Updater.setAuthPane); +// }); +// }; + +// login = () => { +// Updater.login(this.state.user, this.state.pwd) +// .then((ok: boolean) => { +// if (ok) { +// this.update(Updater.setAuthPane); +// this.setState({ user: "", pwd: "" }); +// // close all the panes +// PanesUpdater.displayPane(""); +// this.update(PanesUpdater.updateState); + +// // refresh +// return BrowserUpdater().setHomeItems(); +// } else { +// this.setState({ user: "", pwd: "" }); +// alert("Failed to login."); +// } +// }) +// .then(() => { +// return BrowserUpdater().refreshUploadings(); +// }) +// .then((_: boolean) => { +// this.update(BrowserUpdater().setBrowser); +// }); +// }; + +// logout = () => { +// Updater.logout().then((ok: boolean) => { +// if (ok) { +// this.update(Updater.setAuthPane); +// } else { +// alert("Failed to logout."); +// } +// }); +// }; + +// render() { +// const elements: Array = [ +// , +// , +// , +// ]; + +// return ( +// +//
+// {/*
Login
*/} +// +//
+ +// +// +// +//
+// ); +// } +// } diff --git a/src/client/web/src/components/pane_login.tsx b/src/client/web/src/components/pane_login.tsx index 05c20e4..3b60679 100644 --- a/src/client/web/src/components/pane_login.tsx +++ b/src/client/web/src/components/pane_login.tsx @@ -158,15 +158,16 @@ export class AuthPane extends React.Component { return ( - -
Login
+
+ {/*
Login
*/} - +
+ - diff --git a/src/client/web/src/components/pane_settings.tsx b/src/client/web/src/components/pane_settings.tsx index b68e41f..e0d5284 100644 --- a/src/client/web/src/components/pane_settings.tsx +++ b/src/client/web/src/components/pane_settings.tsx @@ -76,7 +76,7 @@ export class PaneSettings extends React.Component { if (ok) { alert("Password is updated"); } else { - alert("fail to update password"); + alert("Failed to update password"); } this.setState({ oldPwd: "", @@ -120,12 +120,61 @@ export class PaneSettings extends React.Component { ]; return ( -
-
Update Password
- -
+
+
+
+
+
Update Password
+
+
+ +
+
- +
+ +
+
+ + +
+
+ +
+ +
+
+
+
Logout
+
+
+ +
+
+
); } diff --git a/src/client/web/src/components/panes.tsx b/src/client/web/src/components/panes.tsx index b24eec1..3f9d449 100644 --- a/src/client/web/src/components/panes.tsx +++ b/src/client/web/src/components/panes.tsx @@ -64,34 +64,43 @@ export class Panes extends React.Component { } const panesMap: Map = Map({ - settings: , - login: , + settings: ( + + ), + login: ( + + ), }); - const panes = panesMap.keySeq().map( - (paneName: string): JSX.Element => { - const isDisplay = displaying === paneName ? "" : "hidden"; - return ( -
- {panesMap.get(paneName)} -
- ); - } - ); + const panes = panesMap.keySeq().map((paneName: string): JSX.Element => { + const isDisplay = displaying === paneName ? "" : "hidden"; + return ( +
+ {panesMap.get(paneName)} +
+ ); + }); const btnClass = displaying === "login" ? "hidden" : ""; return (
-
-
- -
- {panes}
+ +
+ {panes} + +
); diff --git a/src/client/web/src/components/root_frame.tsx b/src/client/web/src/components/root_frame.tsx index 9e68a0a..28b620c 100644 --- a/src/client/web/src/components/root_frame.tsx +++ b/src/client/web/src/components/root_frame.tsx @@ -3,6 +3,7 @@ import * as React from "react"; import { ICoreState, BaseUpdater } from "./core_state"; import { Browser, Props as BrowserProps } from "./browser"; import { Props as PaneLoginProps } from "./pane_login"; +import { Props as PaneAdminProps } from "./pane_admin"; import { Panes, Props as PanesProps, Updater as PanesUpdater } from "./panes"; export interface Props { @@ -10,6 +11,7 @@ export interface Props { browser: BrowserProps; authPane: PaneLoginProps; panes: PanesProps; + admin: PaneAdminProps; update?: (updater: (prevState: ICoreState) => ICoreState) => void; } diff --git a/src/client/web/src/components/state_mgr.tsx b/src/client/web/src/components/state_mgr.tsx index f21461e..7ba4aed 100644 --- a/src/client/web/src/components/state_mgr.tsx +++ b/src/client/web/src/components/state_mgr.tsx @@ -41,6 +41,7 @@ export class StateMgr extends React.Component { update={this.update} browser={this.state.panel.browser} panes={this.state.panel.panes} + admin={this.state.panel.admin} /> ); }