chore: update initial global loader

This commit is contained in:
Steven 2023-10-08 20:31:38 +08:00
parent 31997936d6
commit 3ff4d19782
4 changed files with 18 additions and 35 deletions

View File

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

View File

@ -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"

View File

@ -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: <App />,
loader: async () => {
await initialGlobalStateLoader();
return null;
},
loader: () => initialGlobalStateLoader(),
children: [
{
path: "/auth",

View File

@ -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));
};