feat(layout): add layout flowgrid

This commit is contained in:
hexxa 2021-10-07 16:17:03 +08:00 committed by Hexxa
parent 02f86c6d99
commit fedd3e6de1
4 changed files with 86 additions and 48 deletions

View file

@ -20,6 +20,7 @@ import { MetadataResp, roleVisitor, roleAdmin } from "../client";
import { Up } from "../worker/upload_mgr"; import { Up } from "../worker/upload_mgr";
import { UploadEntry, UploadState } from "../worker/interface"; import { UploadEntry, UploadState } from "../worker/interface";
import { Flexbox } from "./layout/flexbox"; import { Flexbox } from "./layout/flexbox";
import { Flowgrid } from "./layout/flowgrid";
export interface Item { export interface Item {
name: string; name: string;
@ -86,7 +87,6 @@ export class Browser extends React.Component<Props, State, {}> {
this.uploadInput = ReactDOM.findDOMNode(input); this.uploadInput = ReactDOM.findDOMNode(input);
}; };
this.onClickUpload = () => { this.onClickUpload = () => {
// TODO: check if the re-upload file is same as previous upload
const uploadInput = this.uploadInput as HTMLButtonElement; const uploadInput = this.uploadInput as HTMLButtonElement;
uploadInput.click(); uploadInput.click();
}; };
@ -236,7 +236,10 @@ export class Browser extends React.Component<Props, State, {}> {
}); });
}; };
updateProgress = async (infos: Map<string, UploadEntry>, refresh: boolean) => { updateProgress = async (
infos: Map<string, UploadEntry>,
refresh: boolean
) => {
updater().setUploadings(infos); updater().setUploadings(infos);
let errCount = 0; let errCount = 0;
infos.valueSeq().forEach((entry: UploadEntry) => { infos.valueSeq().forEach((entry: UploadEntry) => {
@ -245,9 +248,11 @@ export class Browser extends React.Component<Props, State, {}> {
if (infos.size === 0 || infos.size === errCount) { if (infos.size === 0 || infos.size === errCount) {
// refresh used space // refresh used space
updater().self().then(() => { updater()
this.update(updater().updateLogin); .self()
}); .then(() => {
this.update(updater().updateLogin);
});
} }
if (refresh) { if (refresh) {
@ -352,8 +357,7 @@ export class Browser extends React.Component<Props, State, {}> {
render() { render() {
const showOp = this.props.login.userRole === roleVisitor ? "hidden" : ""; const showOp = this.props.login.userRole === roleVisitor ? "hidden" : "";
const breadcrumb = this.props.browser.dirPath.map(
let breadcrumb = this.props.browser.dirPath.map(
(pathPart: string, key: number) => { (pathPart: string, key: number) => {
return ( return (
<button <button
@ -369,38 +373,42 @@ export class Browser extends React.Component<Props, State, {}> {
} }
); );
const nameCellClass = `item-name item-name-${this.props.ui.isVertical ? "vertical" : "horizontal" const nameCellClass = `item-name item-name-${
} pointer`; this.props.ui.isVertical ? "vertical" : "horizontal"
} pointer`;
const ops = ( const ops = (
<div> <div>
<div> <Flowgrid
<span className="inline-block margin-t-m margin-b-m"> grids={List([
<input <div className="padding-t-m padding-b-m padding-r-m">
type="text" <input
onChange={this.onInputChange} type="text"
value={this.state.inputValue} onChange={this.onInputChange}
className="black0-font margin-r-m" value={this.state.inputValue}
placeholder={this.props.msg.pkg.get("browser.folder.name")} className="black0-font margin-r-m"
/> placeholder={this.props.msg.pkg.get("browser.folder.name")}
<button onClick={this.onMkDir} className="margin-r-m"> />
{this.props.msg.pkg.get("browser.folder.add")} <button onClick={this.onMkDir} className="margin-r-m">
</button> {this.props.msg.pkg.get("browser.folder.add")}
</span> </button>
<span className="inline-block margin-t-m margin-b-m"> </div>,
<button onClick={this.onClickUpload}>
{this.props.msg.pkg.get("browser.upload")} <div className="padding-t-m padding-b-m">
</button> <button onClick={this.onClickUpload}>
<input {this.props.msg.pkg.get("browser.upload")}
type="file" </button>
onChange={this.addUploads} <input
multiple={true} type="file"
value={this.props.browser.uploadValue} onChange={this.addUploads}
ref={this.assignInput} multiple={true}
className="black0-font hidden" value={this.props.browser.uploadValue}
/> ref={this.assignInput}
</span> className="black0-font hidden"
</div> />
</div>,
])}
/>
</div> </div>
); );
@ -456,8 +464,9 @@ export class Browser extends React.Component<Props, State, {}> {
<span className={`padding-m ${showOp}`}> <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 ? "cyan0-bg white-font" : "grey2-bg grey3-font"
}`}
style={{ width: "8rem", display: "inline-block" }} style={{ width: "8rem", display: "inline-block" }}
> >
{isSelected {isSelected
@ -512,8 +521,9 @@ export class Browser extends React.Component<Props, State, {}> {
<button <button
type="button" type="button"
onClick={() => this.select(item.name)} onClick={() => this.select(item.name)}
className={`${isSelected ? "blue0-bg white-font" : "grey2-bg grey3-font" className={`${
}`} isSelected ? "cyan0-bg white-font" : "grey2-bg grey3-font"
}`}
style={{ width: "8rem", display: "inline-block" }} style={{ width: "8rem", display: "inline-block" }}
> >
{isSelected {isSelected
@ -525,8 +535,9 @@ export class Browser extends React.Component<Props, State, {}> {
childrenStyles={List([{}, { justifyContent: "flex-end" }])} childrenStyles={List([{}, { justifyContent: "flex-end" }])}
/> />
<div <div
className={`${this.state.showDetail.has(item.name) ? "" : "hidden" className={`${
}`} this.state.showDetail.has(item.name) ? "" : "hidden"
}`}
> >
<Flexbox <Flexbox
children={List([ children={List([
@ -793,8 +804,9 @@ export class Browser extends React.Component<Props, State, {}> {
type="text" type="text"
readOnly readOnly
className="margin-r-m" className="margin-r-m"
value={`${document.location.href.split("?")[0] value={`${
}?dir=${encodeURIComponent(dirPath)}`} document.location.href.split("?")[0]
}?dir=${encodeURIComponent(dirPath)}`}
/> />
<button <button
onClick={() => { onClick={() => {

View file

@ -0,0 +1,26 @@
import * as React from "react";
import { List } from "immutable";
export interface Props {
grids: List<JSX.Element>;
style?: React.CSSProperties;
className?: string;
}
export const Flowgrid = (props: Props) => {
const children = props.grids.map(
(child: JSX.Element, i: number): JSX.Element => {
return (
<span key={`flowgrid-${i}`} className="inline-block">
{child}
</span>
);
}
);
return (
<div style={props.style} className={props.className}>
{children}
</div>
);
};

View file

@ -20,9 +20,9 @@ export class StateMgr extends React.Component<Props, State, {}> {
constructor(p: Props) { constructor(p: Props) {
super(p); super(p);
this.state = newState();
const worker = window.Worker == null ? new FgWorker() : new BgWorker(); const worker = window.Worker == null ? new FgWorker() : new BgWorker();
initUploadMgr(worker); initUploadMgr(worker);
this.state = newState();
this.initUpdater(this.state); // don't await this.initUpdater(this.state); // don't await
} }

View file

@ -103,13 +103,13 @@ export class TopBar extends React.Component<Props, State, {}> {
<Flexbox <Flexbox
children={List([ children={List([
<span className={`${showUserInfo}`}> <span className={`${showUserInfo}`}>
<span className="grey3-font font-s"> <span className="grey3-font font-s margin-r-m">
{this.props.login.userName} {this.props.login.userName}
</span> </span>
&nbsp;-&nbsp; {/* &nbsp;-&nbsp;
<span className="grey0-font font-s margin-r-m"> <span className="grey0-font font-s margin-r-m">
{this.props.login.userRole} {this.props.login.userRole}
</span> </span> */}
</span>, </span>,
<button <button