fix(state_updater): share is not enabled, move to initControls

This commit is contained in:
hexxa 2022-01-23 18:51:01 +08:00 committed by Hexxa
parent 8d83ce0209
commit 65da92aece
2 changed files with 11 additions and 12 deletions

View file

@ -161,9 +161,7 @@ describe("State Manager", () => {
}; };
usersCl.isAuthed = jest usersCl.isAuthed = jest
.fn() .fn()
.mockReturnValue( .mockReturnValue(makePromise({ status: 401, statusText: "", data: {} }));
makePromise({ status: 401, statusText: "", data: {} })
);
usersCl.self = jest.fn().mockReturnValue(makePromise(mockSelfResp)); usersCl.self = jest.fn().mockReturnValue(makePromise(mockSelfResp));
const coreState = newState(); const coreState = newState();
@ -187,7 +185,7 @@ describe("State Manager", () => {
expect(coreState.filesInfo.dirPath.join("/")).toEqual(sharingPath); expect(coreState.filesInfo.dirPath.join("/")).toEqual(sharingPath);
expect(coreState.filesInfo.isSharing).toEqual(true); expect(coreState.filesInfo.isSharing).toEqual(true);
expect(coreState.filesInfo.items).toEqual( expect(coreState.filesInfo.items).toEqual(
List(filesResps.listHomeMockResp.data.metadatas) List(filesResps.listMockResp.data.metadatas)
); );
expect(coreState.sharingsInfo.sharings).toEqual(Map<string, string>()); expect(coreState.sharingsInfo.sharings).toEqual(Map<string, string>());
expect(coreState.uploadingsInfo.uploadings).toEqual(List<UploadEntry>([])); expect(coreState.uploadingsInfo.uploadings).toEqual(List<UploadEntry>([]));

View file

@ -420,16 +420,8 @@ export class Updater {
if (shareDir !== "") { if (shareDir !== "") {
// in sharing mode // in sharing mode
const dirPath = List(shareDir.split("/")); const dirPath = List(shareDir.split("/"));
this.props.ui.control.controls = this.props.ui.control.controls.set(
sharingCtrl,
ctrlOn
);
this.props.filesInfo.dirPath = dirPath; this.props.filesInfo.dirPath = dirPath;
} else { } else {
this.props.ui.control.controls = this.props.ui.control.controls.set(
sharingCtrl,
ctrlOff
);
this.props.filesInfo.dirPath = List([]); this.props.filesInfo.dirPath = List([]);
} }
@ -506,6 +498,14 @@ export class Updater {
return paramMap; return paramMap;
}; };
initControls = async (params: Map<string, string>) => {
const shareDir = params.get(shareDirQuery);
this.props.ui.control.controls = this.props.ui.control.controls.set(
sharingCtrl,
shareDir !== "" ? ctrlOn : ctrlOff
);
};
initAuth = async (): Promise<string> => { initAuth = async (): Promise<string> => {
const isAuthedStatus = await this.syncIsAuthed(); const isAuthedStatus = await this.syncIsAuthed();
if (isAuthedStatus !== "") { if (isAuthedStatus !== "") {
@ -537,6 +537,7 @@ export class Updater {
return initClientCfgStatus; return initClientCfgStatus;
} }
this.initControls(paramMap);
this.initUITree(); this.initUITree();
const isInSharingMode = paramMap.get(shareDirQuery) !== ""; const isInSharingMode = paramMap.get(shareDirQuery) !== "";