feat: add user_setting model (#145)

* feat: add `user_setting` model

* chore: add global store

* chore: update settings in web

* chore: update `i18n` example
This commit is contained in:
boojack
2022-08-13 14:35:33 +08:00
committed by GitHub
parent dfac877957
commit 90b881502d
25 changed files with 449 additions and 63 deletions

View File

@ -1,9 +1,13 @@
import { useEffect, useState } from "react";
import useI18n from "./hooks/useI18n";
import { appRouterSwitch } from "./routers";
import { locationService } from "./services";
import { globalService, locationService } from "./services";
import { useAppSelector } from "./store";
import * as storage from "./helpers/storage";
function App() {
const { setLocale } = useI18n();
const global = useAppSelector((state) => state.global);
const pathname = useAppSelector((state) => state.location.pathname);
const [isLoading, setLoading] = useState(true);
@ -12,9 +16,18 @@ function App() {
window.onpopstate = () => {
locationService.updateStateWithLocation();
};
setLoading(false);
globalService.initialState().then(() => {
setLoading(false);
});
}, []);
useEffect(() => {
setLocale(global.locale);
storage.set({
locale: global.locale,
});
}, [global]);
return <>{isLoading ? null : appRouterSwitch(pathname)}</>;
}