1
0
mirror of https://github.com/spacebarchat/client.git synced 2024-11-22 10:22:30 +01:00

refactor: rename RootPage to AppPage and add Loader component

This commit is contained in:
Puyodead1 2023-04-28 15:01:49 -04:00
parent b9417fb653
commit 609d469b20
No known key found for this signature in database
GPG Key ID: A4FA4FEC0DD353FC
4 changed files with 67 additions and 84 deletions

View File

@ -2,15 +2,16 @@ import { observer } from "mobx-react-lite";
import React from "react";
import { Route, Routes, useNavigate } from "react-router-dom";
import { AuthenticationGuard } from "./components/guards/AuthenticationGuard";
import LoadingPage from "./pages/LoadingPage";
import LoginPage from "./pages/LoginPage";
import NotFoundPage from "./pages/NotFound";
import RegistrationPage from "./pages/RegistrationPage";
import { reaction } from "mobx";
import Loader from "./components/Loader";
import { UnauthenticatedGuard } from "./components/guards/UnauthenticatedGuard";
import AppPage from "./pages/AppPage";
import LogoutPage from "./pages/LogoutPage";
import RootPage from "./pages/RootPage";
import ChannelPage from "./pages/subpages/ChannelPage";
import { useAppStore } from "./stores/AppStore";
import { Globals } from "./utils/Globals";
@ -54,36 +55,39 @@ function App() {
},
);
if (app.isAppLoading) {
return <LoadingPage />;
}
return (
<Routes>
<Route
index
path="/"
element={<AuthenticationGuard component={RootPage} />}
/>
<Route
index
path="/app"
element={<AuthenticationGuard component={RootPage} />}
/>
<Route
path="/login"
element={<UnauthenticatedGuard component={LoginPage} />}
/>
<Route
path="/register"
element={<UnauthenticatedGuard component={RegistrationPage} />}
/>
<Route
path="/logout"
element={<AuthenticationGuard component={LogoutPage} />}
/>
<Route path="*" element={<NotFoundPage />} />
</Routes>
<Loader>
<Routes>
<Route
index
path="/"
element={<AuthenticationGuard component={AppPage} />}
/>
<Route
path="/app"
element={<AuthenticationGuard component={AppPage} />}
/>
<Route
path="/channels/:channelId"
element={<AuthenticationGuard component={ChannelPage} />}
/>
<Route
path="/login"
element={<UnauthenticatedGuard component={LoginPage} />}
/>
<Route
path="/register"
element={
<UnauthenticatedGuard component={RegistrationPage} />
}
/>
<Route
path="/logout"
element={<AuthenticationGuard component={LogoutPage} />}
/>
<Route path="*" element={<NotFoundPage />} />
</Routes>
</Loader>
);
}

19
src/components/Loader.tsx Normal file
View File

@ -0,0 +1,19 @@
import { observer } from "mobx-react-lite";
import React from "react";
import LoadingPage from "../pages/LoadingPage";
import { useAppStore } from "../stores/AppStore";
interface Props {
children: React.ReactNode;
}
function Loader(props: Props) {
const app = useAppStore();
if (!app.isReady) {
return <LoadingPage />;
}
return <>{props.children}</>;
}
export default observer(Loader);

13
src/pages/AppPage.tsx Normal file
View File

@ -0,0 +1,13 @@
import { observer } from "mobx-react-lite";
import { Navigate } from "react-router-dom";
import Loader from "../components/Loader";
function AppPage() {
return (
<Loader>
<Navigate to="/channels/@me" />
</Loader>
);
}
export default observer(AppPage);

View File

@ -1,53 +0,0 @@
import { observer } from "mobx-react-lite";
import { useNavigate } from "react-router-dom";
import styled from "styled-components";
import Button from "../components/Button";
import Container from "../components/Container";
import GuildSidebar from "../components/GuildSidebar";
import { useAppStore } from "../stores/AppStore";
import LoadingPage from "./LoadingPage";
const Wrapper = styled(Container)`
display: flex;
flex-direction: row;
`;
const Filler1 = styled.div`
flex: 1;
flex-basis: 330px;
background-color: red;
`;
const Filler2 = styled.div`
flex: 1;
flex-basis: 1170px;
background-color: blue;
`;
const Filler3 = styled.div`
flex: 1;
flex-basis: 348px;
background-color: orange;
`;
function RootPage() {
const app = useAppStore();
const navigate = useNavigate();
if (!app.isReady) {
return <LoadingPage />;
}
return (
<Wrapper>
<GuildSidebar />
<Filler1 />
<Filler2>
<Button onClick={() => navigate("/logout")}>Logout</Button>
</Filler2>
<Filler3 />
</Wrapper>
);
}
export default observer(RootPage);