fix(fe/state_updater): re-order the steps in the initAll
This commit is contained in:
parent
4fb6dd79a3
commit
ba17416755
5 changed files with 67 additions and 25 deletions
|
@ -1,10 +1,35 @@
|
||||||
export class LocalStorage {
|
export interface ILocalStorage {
|
||||||
static get(key: string): string {
|
get: (key: string) => string;
|
||||||
const val = window.localStorage.getItem(key);
|
set: (key: string, val: string) => void;
|
||||||
return val && val != "undefined" && val != "null" ? val : "";
|
}
|
||||||
|
|
||||||
|
export const errNoLocalStorage = "local storage is not supported";
|
||||||
|
|
||||||
|
class LocalStorage {
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
get(key: string): string {
|
||||||
|
if (window != null && window.localStorage != null) {
|
||||||
|
const val = window.localStorage.getItem(key);
|
||||||
|
return val && val != "undefined" && val != "null" ? val : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
static set(key: string, val: string): boolean {
|
|
||||||
window.localStorage.setItem(key, val);
|
set(key: string, val: string) {
|
||||||
return true;
|
if (window != null && window.localStorage != null) {
|
||||||
|
window.localStorage.setItem(key, val);
|
||||||
|
} else {
|
||||||
|
console.error(errNoLocalStorage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var localStorage: LocalStorage;
|
||||||
|
export const Storage = () => {
|
||||||
|
if (localStorage == null) {
|
||||||
|
localStorage = new LocalStorage();
|
||||||
|
}
|
||||||
|
return localStorage;
|
||||||
|
};
|
||||||
|
|
|
@ -67,7 +67,7 @@ export class StateMgr extends React.Component<Props, State, {}> {
|
||||||
.initAll(query)
|
.initAll(query)
|
||||||
.then((status: string) => {
|
.then((status: string) => {
|
||||||
if (status !== "") {
|
if (status !== "") {
|
||||||
alertMsg(getErrMsg(state.msg.pkg, "op.fail", status.toString()));
|
alertMsg(getErrMsg(state.msg.pkg, "op.fail", status));
|
||||||
}
|
}
|
||||||
this.update(updater().updateAll);
|
this.update(updater().updateAll);
|
||||||
});
|
});
|
||||||
|
|
|
@ -31,7 +31,6 @@ import { SettingsClient } from "../client/settings";
|
||||||
import { UploadEntry, UploadState } from "../worker/interface";
|
import { UploadEntry, UploadState } from "../worker/interface";
|
||||||
import { Up } from "../worker/upload_mgr";
|
import { Up } from "../worker/upload_mgr";
|
||||||
import { alertMsg } from "../common/env";
|
import { alertMsg } from "../common/env";
|
||||||
import { LocalStorage } from "../common/localstorage";
|
|
||||||
import { controlName as panelTabs } from "./root_frame";
|
import { controlName as panelTabs } from "./root_frame";
|
||||||
import { settingsTabsCtrl } from "./dialog_settings";
|
import { settingsTabsCtrl } from "./dialog_settings";
|
||||||
import { settingsDialogCtrl } from "./layers";
|
import { settingsDialogCtrl } from "./layers";
|
||||||
|
@ -371,10 +370,7 @@ export class Updater {
|
||||||
};
|
};
|
||||||
|
|
||||||
initStateForVisitor = async (): Promise<any> => {
|
initStateForVisitor = async (): Promise<any> => {
|
||||||
const statuses = await Promise.all([
|
const statuses = await Promise.all([this.getClientCfg()]);
|
||||||
this.getClientCfg(),
|
|
||||||
this.syncIsSharing(this.props.filesInfo.dirPath.join("/")),
|
|
||||||
]);
|
|
||||||
if (statuses.join("") !== "") {
|
if (statuses.join("") !== "") {
|
||||||
return statuses.join(";");
|
return statuses.join(";");
|
||||||
}
|
}
|
||||||
|
@ -449,22 +445,30 @@ export class Updater {
|
||||||
return isAuthedStatus;
|
return isAuthedStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
const statuses = await Promise.all([this.self(), this.initCwd(params)]);
|
|
||||||
if (statuses.join("") !== "") {
|
|
||||||
return statuses.join(";");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.initUITree();
|
|
||||||
const syncCwdStatus = await this.syncCwd();
|
|
||||||
if (syncCwdStatus !== "") {
|
|
||||||
return syncCwdStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
const getCapStatus = await this.getCaptchaID();
|
const getCapStatus = await this.getCaptchaID();
|
||||||
if (getCapStatus !== "") {
|
if (getCapStatus !== "") {
|
||||||
return getCapStatus;
|
return getCapStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const selfStatuses = await Promise.all([this.self(), this.initCwd(params)]);
|
||||||
|
if (selfStatuses.join("") !== "") {
|
||||||
|
return selfStatuses.join(";");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.initUITree();
|
||||||
|
|
||||||
|
const cwdStatus = await this.syncCwd();
|
||||||
|
if (cwdStatus !== "") {
|
||||||
|
return cwdStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isSharingStatus = await this.syncIsSharing(
|
||||||
|
this.props.filesInfo.dirPath.join("/")
|
||||||
|
);
|
||||||
|
if (isSharingStatus !== "") {
|
||||||
|
return isSharingStatus;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.props.login.userRole === roleAdmin) {
|
if (this.props.login.userRole === roleAdmin) {
|
||||||
return this.initStateForAdmin();
|
return this.initStateForAdmin();
|
||||||
} else if (this.props.login.userRole === roleVisitor) {
|
} else if (this.props.login.userRole === roleVisitor) {
|
||||||
|
@ -500,6 +504,7 @@ export class Updater {
|
||||||
|
|
||||||
self = async (): Promise<string> => {
|
self = async (): Promise<string> => {
|
||||||
const resp = await this.usersClient.self();
|
const resp = await this.usersClient.self();
|
||||||
|
|
||||||
if (resp.status === 200) {
|
if (resp.status === 200) {
|
||||||
this.props.login.userID = resp.data.id;
|
this.props.login.userID = resp.data.id;
|
||||||
this.props.login.userName = resp.data.name;
|
this.props.login.userName = resp.data.name;
|
||||||
|
@ -508,7 +513,10 @@ export class Updater {
|
||||||
this.props.login.quota = resp.data.quota;
|
this.props.login.quota = resp.data.quota;
|
||||||
this.props.login.preferences = resp.data.preferences;
|
this.props.login.preferences = resp.data.preferences;
|
||||||
return "";
|
return "";
|
||||||
|
} else if (resp.status === 401) {
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
this.resetUser();
|
this.resetUser();
|
||||||
return errServer;
|
return errServer;
|
||||||
};
|
};
|
||||||
|
|
|
@ -113,4 +113,9 @@ export const msgs: Map<string, string> = Map({
|
||||||
"control.settingsTabs.preferencePane": "Preference",
|
"control.settingsTabs.preferencePane": "Preference",
|
||||||
"upload.add.fail": "Some files conflict with uploading files, please check.",
|
"upload.add.fail": "Some files conflict with uploading files, please check.",
|
||||||
"server.fail": "The operation failed in the server",
|
"server.fail": "The operation failed in the server",
|
||||||
|
"err.updater": "updater error",
|
||||||
|
"err.uploadMgr": "upload Manager error",
|
||||||
|
"err.server": "The operation failed in the server",
|
||||||
|
"err.script.cors": "script error with CORS",
|
||||||
|
"err.unknown": "unknown error",
|
||||||
});
|
});
|
||||||
|
|
|
@ -110,5 +110,9 @@ export const msgs: Map<string, string> = Map({
|
||||||
"control.settingsTabs.managementPane": "管理",
|
"control.settingsTabs.managementPane": "管理",
|
||||||
"control.settingsTabs.preferencePane": "设置",
|
"control.settingsTabs.preferencePane": "设置",
|
||||||
"upload.add.fail": "有些文件与上传任务冲突,请检查",
|
"upload.add.fail": "有些文件与上传任务冲突,请检查",
|
||||||
"server.fail": "操作在服务器端失败",
|
"err.updater": "updater错误",
|
||||||
|
"err.uploadMgr": "upload Manager错误",
|
||||||
|
"err.server": "服务器端操作失败",
|
||||||
|
"err.script.cors": "跨域脚本错误",
|
||||||
|
"err.unknown": "未知错误",
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue