diff --git a/web/src/App.tsx b/web/src/App.tsx index 6129102c..1a80c877 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,32 +1,23 @@ -import { useEffect, useState } from "react"; +import { useEffect } from "react"; +import { RouterProvider } from "react-router-dom"; import useI18n from "./hooks/useI18n"; -import { appRouterSwitch } from "./routers"; import { globalService, locationService } from "./services"; import { useAppSelector } from "./store"; +import router from "./router"; import * as storage from "./helpers/storage"; function App() { const { setLocale } = useI18n(); - const user = useAppSelector((state) => state.user.user); 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(() => { - if (user?.setting.locale) { - globalService.setLocale(user.setting.locale); - } - }, [user?.setting.locale]); + globalService.initialState(); + }, []); useEffect(() => { setLocale(global.locale); @@ -35,7 +26,7 @@ function App() { }); }, [global.locale]); - return <>{isLoading ? null : appRouterSwitch(pathname)}; + return ; } export default App; diff --git a/web/src/components/MenuBtnsPopup.tsx b/web/src/components/MenuBtnsPopup.tsx index 50a76c22..9505ff01 100644 --- a/web/src/components/MenuBtnsPopup.tsx +++ b/web/src/components/MenuBtnsPopup.tsx @@ -1,5 +1,6 @@ import { useEffect, useRef } from "react"; -import { locationService, userService } from "../services"; +import { useNavigate } from "react-router-dom"; +import { userService } from "../services"; import useI18n from "../hooks/useI18n"; import Only from "./common/OnlyWhen"; import showAboutSiteDialog from "./AboutSiteDialog"; @@ -15,6 +16,7 @@ interface Props { const MenuBtnsPopup: React.FC = (props: Props) => { const { shownStatus, setShownStatus } = props; const { t } = useI18n(); + const navigate = useNavigate(); const popupElRef = useRef(null); useEffect(() => { @@ -48,8 +50,7 @@ const MenuBtnsPopup: React.FC = (props: Props) => { userService .doSignOut() .then(() => { - locationService.replaceHistory("/auth"); - window.location.reload(); + navigate("/auth"); }) .catch(() => { // do nth diff --git a/web/src/components/Sidebar.tsx b/web/src/components/Sidebar.tsx index ea029abb..ae1637c7 100644 --- a/web/src/components/Sidebar.tsx +++ b/web/src/components/Sidebar.tsx @@ -1,4 +1,5 @@ -import { locationService, userService } from "../services"; +import { Link } from "react-router-dom"; +import { userService } from "../services"; import useI18n from "../hooks/useI18n"; import Icon from "./Icon"; import Only from "./common/OnlyWhen"; @@ -17,10 +18,6 @@ const Sidebar = () => { showSettingDialog(); }; - const handleExploreBtnClick = () => { - locationService.pushHistory("/explore"); - }; - return (