fix(core_state): reorg ui related state

This commit is contained in:
hexxa 2021-09-27 11:17:03 +08:00 committed by Hexxa
parent ec1bb36c21
commit abbeed24d7
4 changed files with 31 additions and 28 deletions

View file

@ -25,6 +25,7 @@ describe("Browser", () => {
browser: coreState.browser, browser: coreState.browser,
msg: coreState.msg, msg: coreState.msg,
login: coreState.login, login: coreState.login,
ui: coreState.ui,
update: (updater: (prevState: ICoreState) => ICoreState) => {}, update: (updater: (prevState: ICoreState) => ICoreState) => {},
}); });

View file

@ -14,7 +14,7 @@ import { RiEmotionSadLine } from "@react-icons/all-files/ri/RiEmotionSadLine";
import { alertMsg, comfirmMsg } from "../common/env"; 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, UIProps } from "./core_state";
import { LoginProps } from "./pane_login"; import { LoginProps } from "./pane_login";
import { MetadataResp, roleVisitor } from "../client"; import { MetadataResp, roleVisitor } from "../client";
import { Up } from "../worker/upload_mgr"; import { Up } from "../worker/upload_mgr";
@ -40,7 +40,6 @@ export interface BrowserProps {
uploadFiles: List<File>; uploadFiles: List<File>;
uploadValue: string; uploadValue: string;
isVertical: boolean;
tab: string; tab: string;
} }
@ -48,6 +47,7 @@ export interface Props {
browser: BrowserProps; browser: BrowserProps;
msg: MsgProps; msg: MsgProps;
login: LoginProps; login: LoginProps;
ui: UIProps;
update?: (updater: (prevState: ICoreState) => ICoreState) => void; update?: (updater: (prevState: ICoreState) => ICoreState) => void;
} }
@ -350,14 +350,8 @@ export class Browser extends React.Component<Props, State, {}> {
); );
const nameCellClass = `item-name item-name-${ const nameCellClass = `item-name item-name-${
this.props.browser.isVertical ? "vertical" : "horizontal" this.props.ui.isVertical ? "vertical" : "horizontal"
} pointer`; } pointer`;
const sizeCellClass = this.props.browser.isVertical
? `hidden margin-s`
: ``;
const modTimeCellClass = this.props.browser.isVertical
? `hidden margin-s`
: ``;
const ops = ( const ops = (
<div> <div>

View file

@ -19,13 +19,15 @@ export interface MsgProps {
} }
export interface UIProps { export interface UIProps {
wallpaper: string; isVertical: boolean;
repeat: string; bg: {
position: string; url: string;
align: string; repeat: string;
position: string;
align: string;
};
} }
export interface ICoreState { export interface ICoreState {
isVertical: boolean;
browser: BrowserProps; browser: BrowserProps;
panes: PanesProps; panes: PanesProps;
login: LoginProps; login: LoginProps;
@ -48,9 +50,7 @@ export function newState(): ICoreState {
export function initState(): ICoreState { export function initState(): ICoreState {
return { return {
isVertical: isVertical(),
browser: { browser: {
isVertical: isVertical(),
dirPath: List<string>(["."]), dirPath: List<string>(["."]),
items: List<MetadataResp>([]), items: List<MetadataResp>([]),
sharings: List<string>([]), sharings: List<string>([]),
@ -61,7 +61,9 @@ export function initState(): ICoreState {
tab: "", tab: "",
}, },
panes: { panes: {
// which pane is displaying
displaying: "browser", displaying: "browser",
// which panes can be displayed
paneNames: Set<string>([]), // "settings", "login", "admin" paneNames: Set<string>([]), // "settings", "login", "admin"
}, },
login: { login: {
@ -86,10 +88,13 @@ export function initState(): ICoreState {
pkg: MsgPackage.get("en_US"), pkg: MsgPackage.get("en_US"),
}, },
ui: { ui: {
wallpaper: "", isVertical: isVertical(),
repeat: "", bg: {
position: "", url: "",
align: "", repeat: "",
position: "",
align: "",
},
}, },
}; };
} }

View file

@ -8,7 +8,6 @@ import { AdminProps } from "./pane_admin";
import { TopBar } from "./topbar"; import { TopBar } from "./topbar";
import { roleVisitor } from "../client"; import { roleVisitor } from "../client";
export interface Props { export interface Props {
browser: BrowserProps; browser: BrowserProps;
panes: PanesProps; panes: PanesProps;
@ -19,25 +18,28 @@ export interface Props {
update?: (updater: (prevState: ICoreState) => ICoreState) => void; update?: (updater: (prevState: ICoreState) => ICoreState) => void;
} }
export interface State { } export interface State {}
export class RootFrame extends React.Component<Props, State, {}> { export class RootFrame extends React.Component<Props, State, {}> {
constructor(p: Props) { constructor(p: Props) {
super(p); super(p);
} }
render() { render() {
const wallpaperStyle = const bgStyle =
this.props.ui.wallpaper !== "" this.props.ui.bg.url !== ""
? { ? {
background: `url("${this.props.ui.wallpaper}") ${this.props.ui.repeat} ${this.props.ui.position} ${this.props.ui.align}`, background: `url("${this.props.ui.bg.url}") ${this.props.ui.bg.repeat} ${this.props.ui.bg.position} ${this.props.ui.bg.align}`,
} }
: {}; : {};
const showBrowser = this.props.login.userRole === roleVisitor && !this.props.browser.isSharing ? "hidden" : ""; 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={bgStyle}>
<Panes <Panes
panes={this.props.panes} panes={this.props.panes}
login={this.props.login} login={this.props.login}
@ -58,6 +60,7 @@ export class RootFrame extends React.Component<Props, State, {}> {
browser={this.props.browser} browser={this.props.browser}
msg={this.props.msg} msg={this.props.msg}
login={this.props.login} login={this.props.login}
ui={this.props.ui}
update={this.props.update} update={this.props.update}
/> />
</div> </div>