diff --git a/src/client/web/src/components/browser.tsx b/src/client/web/src/components/browser.tsx index 05aeb06..e9c7319 100644 --- a/src/client/web/src/components/browser.tsx +++ b/src/client/web/src/components/browser.tsx @@ -16,8 +16,6 @@ import { import { Up } from "../worker/upload_mgr"; import { UploadEntry } from "../worker/interface"; -export const uploadCheckCycle = 1000; - export interface Item { name: string; size: number; @@ -28,8 +26,10 @@ export interface Item { export interface Props { dirPath: List; + isSharing: boolean; items: List; uploadings: List; + sharings: List; uploadFiles: List; uploadValue: string; @@ -191,6 +191,12 @@ export class Browser extends React.Component { updater() .setItems(dirPath) + .then(() => { + updater().listSharings(); + }) + .then(() => { + updater().setSharing(dirPath.join("/")); + }) .then(() => { this.update(updater().setBrowser); }); @@ -235,6 +241,40 @@ export class Browser extends React.Component { }); }; + addSharing = () => { + updater() + .addSharing() + .then((ok) => { + if (!ok) { + alert("failed to enable sharing"); + } else { + this.listSharings(); + } + }); + }; + + deleteSharing = (dirPath: string) => { + updater() + .deleteSharing(dirPath) + .then((ok) => { + if (!ok) { + alert("failed to disable sharing"); + } else { + this.listSharings(); + } + }); + }; + + listSharings = () => { + updater() + .listSharings() + .then((ok) => { + if (ok) { + this.update(updater().setBrowser); + } + }); + }; + render() { const breadcrumb = this.props.dirPath.map( (pathPart: string, key: number) => { @@ -308,10 +348,29 @@ export class Browser extends React.Component { + {this.props.isSharing ? ( + + ) : ( + + )} ); @@ -418,6 +477,24 @@ export class Browser extends React.Component { ); }); + const sharingList = this.props.sharings.map((dirPath: string) => { +
+ {dirPath} + + + +
; + }); + + console.log("browser", this.props.sharings, this.props.isSharing); + return (
@@ -432,7 +509,7 @@ export class Browser extends React.Component { backgroundColor: "rgba(0, 0, 0, 0.7)", padding: "0.8rem 1rem", fontWeight: "bold", - borderRadius: "0.5rem" + borderRadius: "0.5rem", }} > Location: @@ -453,6 +530,19 @@ export class Browser extends React.Component {
)} + {this.props.sharings.size === 0 ? null : ( +
+
+ + + Uploading Files + + +
+ {sharingList} +
+ )} +
diff --git a/src/client/web/src/components/browser.updater.ts b/src/client/web/src/components/browser.updater.ts index 3cde045..ea9176e 100644 --- a/src/client/web/src/components/browser.updater.ts +++ b/src/client/web/src/components/browser.updater.ts @@ -25,21 +25,18 @@ export class Updater { } initUploads = () => { - this.props.uploadings.forEach(entry => { + this.props.uploadings.forEach((entry) => { Up().addStopped(entry.realFilePath, entry.uploaded, entry.size); - }) + }); // this.setUploadings(Up().list()); }; addUploads = (fileList: List) => { - fileList.forEach(file => { - const filePath = getItemPath( - this.props.dirPath.join("/"), - file.name - ); + fileList.forEach((file) => { + const filePath = getItemPath(this.props.dirPath.join("/"), file.name); // do not wait for the promise Up().add(file, filePath); - }) + }); this.setUploadings(Up().list()); }; @@ -51,18 +48,42 @@ export class Updater { setUploadings = (infos: Map) => { this.props.uploadings = List( - infos.valueSeq().map( - (v: UploadEntry): UploadInfo => { - return { - realFilePath: v.filePath, - size: v.size, - uploaded: v.uploaded, - }; - } - ) + infos.valueSeq().map((v: UploadEntry): UploadInfo => { + return { + realFilePath: v.filePath, + size: v.size, + uploaded: v.uploaded, + }; + }) ); }; + addSharing = async (): Promise => { + const dirPath = this.props.dirPath.join("/"); + const resp = await this.filesClient.addSharing(dirPath); + return resp.status === 200; + }; + + deleteSharing = async (dirPath: string): Promise => { + const resp = await this.filesClient.addSharing(dirPath); + return resp.status === 200; + }; + + setSharing = async (dirPath: string): Promise => { + const resp = await this.filesClient.isSharing(dirPath); + this.props.isSharing = resp.status === 200; + return resp.status === 200; // TODO: differentiate 404 and error + }; + + listSharings = async (): Promise => { + const resp = await this.filesClient.listSharings(); + this.props.sharings = + resp.status === 200 + ? List(resp.data.sharingDirs) + : this.props.sharings; + return resp.status === 200; + }; + refreshUploadings = async (): Promise => { const luResp = await this.filesClient.listUploadings(); @@ -93,13 +114,11 @@ export class Updater { .filter((item) => { return selectedItems.has(item.name); }) - .map( - async (selectedItem: MetadataResp): Promise => { - const itemPath = getItemPath(dirParts.join("/"), selectedItem.name); - const resp = await this.filesClient.delete(itemPath); - return resp.status === 200 ? "" : selectedItem.name; - } - ); + .map(async (selectedItem: MetadataResp): Promise => { + const itemPath = getItemPath(dirParts.join("/"), selectedItem.name); + const resp = await this.filesClient.delete(itemPath); + return resp.status === 200 ? "" : selectedItem.name; + }); const failedFiles = await Promise.all(delRequests); failedFiles.forEach((failedFile) => { @@ -156,8 +175,13 @@ export class Updater { }; setBrowser = (prevState: ICoreState): ICoreState => { - prevState.panel.browser = { ...prevState.panel, ...this.props }; - return prevState; + return { + ...prevState, + panel: { + ...prevState.panel, + browser: { ...this.props }, // TODO: use spread + }, + }; }; } diff --git a/src/client/web/src/components/core_state.ts b/src/client/web/src/components/core_state.ts index 24b0e78..9f917b0 100644 --- a/src/client/web/src/components/core_state.ts +++ b/src/client/web/src/components/core_state.ts @@ -56,6 +56,8 @@ export function initState(): ICoreState { isVertical: isVertical(), dirPath: List(["."]), items: List([]), + sharings: List([]), + isSharing: false, uploadings: List([]), uploadValue: "", uploadFiles: List([]), @@ -91,6 +93,8 @@ export function mockState(): ICoreState { isVertical: false, dirPath: List(["."]), items: List([]), + sharings: List([]), + isSharing: false, uploadings: List([]), uploadValue: "", uploadFiles: List([]), diff --git a/src/client/web/src/components/pane_admin.tsx b/src/client/web/src/components/pane_admin.tsx index 8d88d0a..0587f43 100644 --- a/src/client/web/src/components/pane_admin.tsx +++ b/src/client/web/src/components/pane_admin.tsx @@ -377,7 +377,7 @@ export class AdminPane extends React.Component { render() { const userList = this.props.users.valueSeq().map((user: User) => { return ( -
+
{ .then(() => { return BrowserUpdater().refreshUploadings(); }) + .then(() => { + return BrowserUpdater().setSharing( + BrowserUpdater().props.dirPath.join("/") + ); + }) + .then(() => { + return BrowserUpdater().listSharings(); + }) .then((_: boolean) => { this.update(BrowserUpdater().setBrowser); }); diff --git a/src/client/web/src/components/panes.tsx b/src/client/web/src/components/panes.tsx index 07f378b..d9b1c6f 100644 --- a/src/client/web/src/components/panes.tsx +++ b/src/client/web/src/components/panes.tsx @@ -117,7 +117,6 @@ export class Updater { }; static updateState = (prevState: ICoreState): ICoreState => { - console.log(prevState, Updater.props); return { ...prevState, panel: { diff --git a/src/client/web/src/components/root_frame.tsx b/src/client/web/src/components/root_frame.tsx index e15cc95..a61368e 100644 --- a/src/client/web/src/components/root_frame.tsx +++ b/src/client/web/src/components/root_frame.tsx @@ -43,6 +43,8 @@ export class RootFrame extends React.Component { render() { const update = this.props.update; + console.log("rootframe", this.props.browser.isSharing); + return (
@@ -88,6 +90,8 @@ export class RootFrame extends React.Component { dirPath={this.props.browser.dirPath} items={this.props.browser.items} uploadings={this.props.browser.uploadings} + sharings={this.props.browser.sharings} + isSharing={this.props.browser.isSharing} update={update} uploadFiles={this.props.browser.uploadFiles} uploadValue={this.props.browser.uploadValue} diff --git a/src/client/web/src/components/state_mgr.tsx b/src/client/web/src/components/state_mgr.tsx index 6fb1aa2..410c1c2 100644 --- a/src/client/web/src/components/state_mgr.tsx +++ b/src/client/web/src/components/state_mgr.tsx @@ -24,15 +24,13 @@ export class StateMgr extends React.Component { LoginPaneUpdater.init(state.panel.authPane); LoginPaneUpdater.setClient(new UsersClient("")); - LoginPaneUpdater.getCaptchaID() - .then((ok: boolean) => { - if (!ok) { - alert("failed to get captcha id"); - } else { - this.update(LoginPaneUpdater.setAuthPane); - console.log(LoginPaneUpdater) - } - }); + LoginPaneUpdater.getCaptchaID().then((ok: boolean) => { + if (!ok) { + alert("failed to get captcha id"); + } else { + this.update(LoginPaneUpdater.setAuthPane); + } + }); BrowserUpdater() .setHomeItems() @@ -42,28 +40,42 @@ export class StateMgr extends React.Component { .then((_: boolean) => { BrowserUpdater().initUploads(); }) + .then(() => { + BrowserUpdater().setSharing(BrowserUpdater().props.dirPath.join("/")); + }) + .then(() => { + BrowserUpdater().listSharings(); + }) .then(() => { this.update(BrowserUpdater().setBrowser); + console.log("0", this.state, BrowserUpdater().props); }) .then(() => { - return PanesUpdater.self(); + PanesUpdater.self(); + console.log("1", this.state); }) .then(() => { - return PanesUpdater.listRoles(); + PanesUpdater.listRoles(); + console.log("2", this.state); }) - .then((_: boolean) => { - return PanesUpdater.listUsers(); + .then(() => { + PanesUpdater.listUsers(); + console.log("3", this.state); }) - .then((_: boolean) => { + .then(() => { this.update(PanesUpdater.updateState); + console.log("final", this.state); }); }; update = (apply: (prevState: ICoreState) => ICoreState): void => { this.setState(apply(this.state)); + console.log("core", this.state); }; render() { + console.log("state_mgr", this.state.panel.browser.isSharing); + return (