You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
memos/web/src/pages/Home.tsx

46 lines
1.1 KiB
TypeScript

import { useEffect } from "react";
4 years ago
import { locationService, userService } from "../services";
import { homeRouterSwitch } from "../routers";
import { useAppSelector } from "../store";
4 years ago
import Sidebar from "../components/Sidebar";
import useLoading from "../hooks/useLoading";
import "../less/home.less";
function Home() {
const pathname = useAppSelector((state) => state.location.pathname);
4 years ago
const loadingState = useLoading();
useEffect(() => {
const { user } = userService.getState();
if (!user) {
userService
.doSignIn()
.catch(() => {
// do nth
})
.finally(() => {
if (userService.getState().user) {
loadingState.setFinish();
} else {
locationService.replaceHistory("/signin");
}
});
} else {
loadingState.setFinish();
}
}, []);
return (
<>
{loadingState.isLoading ? null : (
<section id="page-wrapper">
<Sidebar />
{homeRouterSwitch(pathname)}
4 years ago
</section>
)}
</>
);
}
export default Home;