fix(fe/files): sharings info is not updated

This commit is contained in:
hexxa 2021-12-12 12:23:04 +08:00 committed by Hexxa
parent 25a2fdad04
commit ee0fcb5691
4 changed files with 45 additions and 21 deletions

View file

@ -1,4 +1,3 @@
import { mock, instance, verify, when, anything } from "ts-mockito";
import { List } from "immutable"; import { List } from "immutable";
import { initMockWorker } from "../../test/helpers"; import { initMockWorker } from "../../test/helpers";
@ -39,20 +38,8 @@ describe("FilesPanel", () => {
test("chdir", async () => { test("chdir", async () => {
const { filesPanel, usersCl, filesCl } = initFilesPanel(); const { filesPanel, usersCl, filesCl } = initFilesPanel();
const newSharings = ["mock_sharingfolder1", "mock_sharingfolder2"];
const newCwd = List(["newPos", "subFolder"]); const newCwd = List(["newPos", "subFolder"]);
filesCl.setMock({
...filesResps,
listSharingsMockResp: {
status: 200,
statusText: "",
data: {
sharingDirs: newSharings,
},
},
});
await filesPanel.chdir(newCwd); await filesPanel.chdir(newCwd);
expect(updater().props.filesInfo.dirPath).toEqual(newCwd); expect(updater().props.filesInfo.dirPath).toEqual(newCwd);
@ -60,8 +47,31 @@ describe("FilesPanel", () => {
expect(updater().props.filesInfo.items).toEqual( expect(updater().props.filesInfo.items).toEqual(
List(filesResps.listHomeMockResp.data.metadatas) 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( expect(updater().props.sharingsInfo.sharings).toEqual(
List(filesResps.listSharingsMockResp.data.sharingDirs) List(sharingDirs)
); );
}); });
}); });

View file

@ -128,8 +128,6 @@ export class FilesPanel extends React.Component<Props, State, {}> {
} }
updater().addUploads(fileList); updater().addUploads(fileList);
this.props.update(updater().updateUploadingsInfo); this.props.update(updater().updateUploadingsInfo);
// this.props.update(updater().updateFilesInfo);
// this.props.update(updater().updateSharingsInfo);
}; };
onNewFolderNameChange = (ev: React.ChangeEvent<HTMLInputElement>) => { onNewFolderNameChange = (ev: React.ChangeEvent<HTMLInputElement>) => {
@ -308,11 +306,12 @@ export class FilesPanel extends React.Component<Props, State, {}> {
alertMsg(this.props.msg.pkg.get("browser.share.add.fail")); alertMsg(this.props.msg.pkg.get("browser.share.add.fail"));
} else { } else {
updater().setSharing(true); updater().setSharing(true);
return updater().listSharings();
} }
}) })
.then(() => { .then(() => {
this.props.update(updater().updateFilesInfo);
this.props.update(updater().updateSharingsInfo); this.props.update(updater().updateSharingsInfo);
this.props.update(updater().updateFilesInfo);
}); });
}; };
@ -324,11 +323,12 @@ export class FilesPanel extends React.Component<Props, State, {}> {
alertMsg(this.props.msg.pkg.get("browser.share.del.fail")); alertMsg(this.props.msg.pkg.get("browser.share.del.fail"));
} else { } else {
updater().setSharing(false); updater().setSharing(false);
return updater().listSharings();
} }
}) })
.then(() => { .then(() => {
this.props.update(updater().updateFilesInfo);
this.props.update(updater().updateSharingsInfo); this.props.update(updater().updateSharingsInfo);
this.props.update(updater().updateFilesInfo);
}); });
}; };

View file

@ -74,8 +74,8 @@ export class StateMgr extends React.Component<Props, State, {}> {
}); });
}; };
update = (apply: (prevState: ICoreState) => ICoreState): void => { update = (update: (prevState: ICoreState) => ICoreState): void => {
this.setState(apply(this.state)); this.setState(update(this.state));
}; };
render() { render() {

View file

@ -63,7 +63,6 @@ export class Updater {
this.props.uploadingsInfo.uploadings.forEach((entry) => { this.props.uploadingsInfo.uploadings.forEach((entry) => {
Up().addStopped(entry.filePath, entry.uploaded, entry.size); Up().addStopped(entry.filePath, entry.uploaded, entry.size);
}); });
// this.setUploadings(Up().list());
}; };
addUploads = (fileList: List<File>) => { addUploads = (fileList: List<File>) => {
@ -705,6 +704,21 @@ export class Updater {
return resp.status; 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 => { updateFilesInfo = (prevState: ICoreState): ICoreState => {
return { return {
...prevState, ...prevState,