memos/web/src/App.tsx
boojack 90b881502d
feat: add user_setting model (#145)
* feat: add `user_setting` model

* chore: add global store

* chore: update settings in web

* chore: update `i18n` example
2022-08-13 14:35:33 +08:00

34 lines
963 B
TypeScript

import { useEffect, useState } from "react";
import useI18n from "./hooks/useI18n";
import { appRouterSwitch } from "./routers";
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);
useEffect(() => {
locationService.updateStateWithLocation();
window.onpopstate = () => {
locationService.updateStateWithLocation();
};
globalService.initialState().then(() => {
setLoading(false);
});
}, []);
useEffect(() => {
setLocale(global.locale);
storage.set({
locale: global.locale,
});
}, [global]);
return <>{isLoading ? null : appRouterSwitch(pathname)}</>;
}
export default App;