chore: update initial global loader

pull/2363/head
Steven 2 years ago
parent 31997936d6
commit 3ff4d19782

@ -1,6 +1,6 @@
{ {
"short_name": "Memos", "short_name": "memos",
"name": "Memos", "name": "memos",
"description": "usememos/memos", "description": "usememos/memos",
"icons": [ "icons": [
{ {

@ -320,8 +320,8 @@
"days": "days" "days": "days"
}, },
"about": { "about": {
"about-memos": "About Memos", "about-memos": "About memos",
"memos-description": "Memos is a web-based note-taking application that you can use to write, organize, and share notes.", "memos-description": "memos is a web-based note-taking application that you can use to write, organize, and share notes.",
"no-server-description": "No description configured for this server.", "no-server-description": "No description configured for this server.",
"powered-by": "Powered by", "powered-by": "Powered by",
"other-projects": "Other Projects" "other-projects": "Other Projects"

@ -18,21 +18,14 @@ const Resources = lazy(() => import("@/pages/Resources"));
const Setting = lazy(() => import("@/pages/Setting")); const Setting = lazy(() => import("@/pages/Setting"));
const NotFound = lazy(() => import("@/pages/NotFound")); const NotFound = lazy(() => import("@/pages/NotFound"));
const initialGlobalStateLoader = (() => { const initialGlobalStateLoader = async () => {
let done = false; try {
await initialGlobalState();
return async () => { } catch (error) {
if (done) { // do nth
return; }
} return null;
done = true; };
try {
await initialGlobalState();
} catch (error) {
// do nth
}
};
})();
const initialUserStateLoader = async (redirectWhenNotFound = true) => { const initialUserStateLoader = async (redirectWhenNotFound = true) => {
let user = undefined; let user = undefined;
@ -52,10 +45,7 @@ const router = createBrowserRouter([
{ {
path: "/", path: "/",
element: <App />, element: <App />,
loader: async () => { loader: () => initialGlobalStateLoader(),
await initialGlobalStateLoader();
return null;
},
children: [ children: [
{ {
path: "/auth", path: "/auth",

@ -7,9 +7,10 @@ import store, { useAppSelector } from "../";
import { setAppearance, setGlobalState, setLocale } from "../reducer/global"; import { setAppearance, setGlobalState, setLocale } from "../reducer/global";
export const initialGlobalState = async () => { export const initialGlobalState = async () => {
const { locale: storageLocale, appearance: storageAppearance } = storage.get(["locale", "appearance"]);
const defaultGlobalState = { const defaultGlobalState = {
locale: "en" as Locale, locale: (storageLocale || "en") as Locale,
appearance: "system" as Appearance, appearance: (storageAppearance || "system") as Appearance,
systemStatus: { systemStatus: {
allowSignUp: false, allowSignUp: false,
disablePasswordLogin: false, disablePasswordLogin: false,
@ -30,14 +31,6 @@ export const initialGlobalState = async () => {
} as SystemStatus, } as SystemStatus,
}; };
const { locale: storageLocale, appearance: storageAppearance } = storage.get(["locale", "appearance"]);
if (storageLocale) {
defaultGlobalState.locale = storageLocale;
}
if (storageAppearance) {
defaultGlobalState.appearance = storageAppearance;
}
const { data } = await api.getSystemStatus(); const { data } = await api.getSystemStatus();
if (data) { if (data) {
const customizedProfile = data.customizedProfile; const customizedProfile = data.customizedProfile;
@ -53,8 +46,8 @@ export const initialGlobalState = async () => {
}, },
}; };
defaultGlobalState.locale = defaultGlobalState.locale =
storageLocale || defaultGlobalState.systemStatus.customizedProfile.locale || findNearestLanguageMatch(i18n.language); defaultGlobalState.locale || defaultGlobalState.systemStatus.customizedProfile.locale || findNearestLanguageMatch(i18n.language);
defaultGlobalState.appearance = defaultGlobalState.systemStatus.customizedProfile.appearance; defaultGlobalState.appearance = defaultGlobalState.appearance || defaultGlobalState.systemStatus.customizedProfile.appearance;
} }
store.dispatch(setGlobalState(defaultGlobalState)); store.dispatch(setGlobalState(defaultGlobalState));
}; };

Loading…
Cancel
Save