From 3ff4d197821b9c7932e4ede0c85ef943049fb9b4 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Oct 2023 20:31:38 +0800 Subject: [PATCH] chore: update initial global loader --- web/public/manifest.json | 4 ++-- web/src/locales/en.json | 4 ++-- web/src/router/index.tsx | 28 +++++++++------------------- web/src/store/module/global.ts | 17 +++++------------ 4 files changed, 18 insertions(+), 35 deletions(-) diff --git a/web/public/manifest.json b/web/public/manifest.json index 5a3982ad..5b74785c 100644 --- a/web/public/manifest.json +++ b/web/public/manifest.json @@ -1,6 +1,6 @@ { - "short_name": "Memos", - "name": "Memos", + "short_name": "memos", + "name": "memos", "description": "usememos/memos", "icons": [ { diff --git a/web/src/locales/en.json b/web/src/locales/en.json index faa58849..8d27cbf1 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -320,8 +320,8 @@ "days": "days" }, "about": { - "about-memos": "About Memos", - "memos-description": "Memos is a web-based note-taking application that you can use to write, organize, and share notes.", + "about-memos": "About memos", + "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.", "powered-by": "Powered by", "other-projects": "Other Projects" diff --git a/web/src/router/index.tsx b/web/src/router/index.tsx index 3ff51f63..26504218 100644 --- a/web/src/router/index.tsx +++ b/web/src/router/index.tsx @@ -18,21 +18,14 @@ const Resources = lazy(() => import("@/pages/Resources")); const Setting = lazy(() => import("@/pages/Setting")); const NotFound = lazy(() => import("@/pages/NotFound")); -const initialGlobalStateLoader = (() => { - let done = false; - - return async () => { - if (done) { - return; - } - done = true; - try { - await initialGlobalState(); - } catch (error) { - // do nth - } - }; -})(); +const initialGlobalStateLoader = async () => { + try { + await initialGlobalState(); + } catch (error) { + // do nth + } + return null; +}; const initialUserStateLoader = async (redirectWhenNotFound = true) => { let user = undefined; @@ -52,10 +45,7 @@ const router = createBrowserRouter([ { path: "/", element: , - loader: async () => { - await initialGlobalStateLoader(); - return null; - }, + loader: () => initialGlobalStateLoader(), children: [ { path: "/auth", diff --git a/web/src/store/module/global.ts b/web/src/store/module/global.ts index 48d25347..495a802a 100644 --- a/web/src/store/module/global.ts +++ b/web/src/store/module/global.ts @@ -7,9 +7,10 @@ import store, { useAppSelector } from "../"; import { setAppearance, setGlobalState, setLocale } from "../reducer/global"; export const initialGlobalState = async () => { + const { locale: storageLocale, appearance: storageAppearance } = storage.get(["locale", "appearance"]); const defaultGlobalState = { - locale: "en" as Locale, - appearance: "system" as Appearance, + locale: (storageLocale || "en") as Locale, + appearance: (storageAppearance || "system") as Appearance, systemStatus: { allowSignUp: false, disablePasswordLogin: false, @@ -30,14 +31,6 @@ export const initialGlobalState = async () => { } 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(); if (data) { const customizedProfile = data.customizedProfile; @@ -53,8 +46,8 @@ export const initialGlobalState = async () => { }, }; defaultGlobalState.locale = - storageLocale || defaultGlobalState.systemStatus.customizedProfile.locale || findNearestLanguageMatch(i18n.language); - defaultGlobalState.appearance = defaultGlobalState.systemStatus.customizedProfile.appearance; + defaultGlobalState.locale || defaultGlobalState.systemStatus.customizedProfile.locale || findNearestLanguageMatch(i18n.language); + defaultGlobalState.appearance = defaultGlobalState.appearance || defaultGlobalState.systemStatus.customizedProfile.appearance; } store.dispatch(setGlobalState(defaultGlobalState)); };