diff --git a/src/client/web/src/components/__test__/panel_files.test.tsx b/src/client/web/src/components/__test__/panel_files.test.tsx index c97e407..1db2793 100644 --- a/src/client/web/src/components/__test__/panel_files.test.tsx +++ b/src/client/web/src/components/__test__/panel_files.test.tsx @@ -1,4 +1,3 @@ -import { mock, instance, verify, when, anything } from "ts-mockito"; import { List } from "immutable"; import { initMockWorker } from "../../test/helpers"; @@ -39,20 +38,8 @@ describe("FilesPanel", () => { test("chdir", async () => { const { filesPanel, usersCl, filesCl } = initFilesPanel(); - const newSharings = ["mock_sharingfolder1", "mock_sharingfolder2"]; const newCwd = List(["newPos", "subFolder"]); - filesCl.setMock({ - ...filesResps, - listSharingsMockResp: { - status: 200, - statusText: "", - data: { - sharingDirs: newSharings, - }, - }, - }); - await filesPanel.chdir(newCwd); expect(updater().props.filesInfo.dirPath).toEqual(newCwd); @@ -60,8 +47,31 @@ describe("FilesPanel", () => { expect(updater().props.filesInfo.items).toEqual( List(filesResps.listHomeMockResp.data.metadatas) ); + }); + + test("addSharing", async () => { + const { filesPanel, usersCl, filesCl } = initFilesPanel(); + + const newSharingPath = List(["newPos", "subFolder"]); + const sharingDirs = [newSharingPath.join("/")]; + + filesCl.setMock({ + ...filesResps, + listSharingsMockResp: { + status: 200, + statusText: "", + data: { + sharingDirs: sharingDirs, + }, + }, + }); + + await filesPanel.addSharing(newSharingPath); + + + expect(updater().props.filesInfo.isSharing).toEqual(true); expect(updater().props.sharingsInfo.sharings).toEqual( - List(filesResps.listSharingsMockResp.data.sharingDirs) + List(sharingDirs) ); }); }); diff --git a/src/client/web/src/components/panel_files.tsx b/src/client/web/src/components/panel_files.tsx index d2df355..8f0d030 100644 --- a/src/client/web/src/components/panel_files.tsx +++ b/src/client/web/src/components/panel_files.tsx @@ -128,8 +128,6 @@ export class FilesPanel extends React.Component { } updater().addUploads(fileList); this.props.update(updater().updateUploadingsInfo); - // this.props.update(updater().updateFilesInfo); - // this.props.update(updater().updateSharingsInfo); }; onNewFolderNameChange = (ev: React.ChangeEvent) => { @@ -308,11 +306,12 @@ export class FilesPanel extends React.Component { alertMsg(this.props.msg.pkg.get("browser.share.add.fail")); } else { updater().setSharing(true); + return updater().listSharings(); } }) .then(() => { - this.props.update(updater().updateFilesInfo); this.props.update(updater().updateSharingsInfo); + this.props.update(updater().updateFilesInfo); }); }; @@ -324,11 +323,12 @@ export class FilesPanel extends React.Component { alertMsg(this.props.msg.pkg.get("browser.share.del.fail")); } else { updater().setSharing(false); + return updater().listSharings(); } }) .then(() => { - this.props.update(updater().updateFilesInfo); this.props.update(updater().updateSharingsInfo); + this.props.update(updater().updateFilesInfo); }); }; diff --git a/src/client/web/src/components/state_mgr.tsx b/src/client/web/src/components/state_mgr.tsx index cbd44e9..43e051a 100644 --- a/src/client/web/src/components/state_mgr.tsx +++ b/src/client/web/src/components/state_mgr.tsx @@ -74,8 +74,8 @@ export class StateMgr extends React.Component { }); }; - update = (apply: (prevState: ICoreState) => ICoreState): void => { - this.setState(apply(this.state)); + update = (update: (prevState: ICoreState) => ICoreState): void => { + this.setState(update(this.state)); }; render() { diff --git a/src/client/web/src/components/state_updater.ts b/src/client/web/src/components/state_updater.ts index 9c6a5a0..9d198a6 100644 --- a/src/client/web/src/components/state_updater.ts +++ b/src/client/web/src/components/state_updater.ts @@ -63,7 +63,6 @@ export class Updater { this.props.uploadingsInfo.uploadings.forEach((entry) => { Up().addStopped(entry.filePath, entry.uploaded, entry.size); }); - // this.setUploadings(Up().list()); }; addUploads = (fileList: List) => { @@ -705,6 +704,21 @@ export class Updater { return resp.status; }; + updateAll = (prevState: ICoreState): ICoreState => { + return { + filesInfo: { ...prevState.filesInfo, ...this.props.filesInfo }, + uploadingsInfo: { + ...prevState.uploadingsInfo, + ...this.props.uploadingsInfo, + }, + sharingsInfo: { ...prevState.sharingsInfo, ...this.props.sharingsInfo }, + login: { ...prevState.login, ...this.props.login }, + admin: { ...prevState.admin, ...this.props.admin }, + msg: { ...prevState.msg, ...this.props.msg }, + ui: { ...prevState.ui, ...this.props.ui }, + }; + }; + updateFilesInfo = (prevState: ICoreState): ICoreState => { return { ...prevState,