Skip to content

Commit

Permalink
Fix router (#449)
Browse files Browse the repository at this point in the history
* Restructured router

* Deleted duplicated route

* Restructured folders
  • Loading branch information
bzzz-coding authored Sep 8, 2023
1 parent 5f88a53 commit 8b75cfb
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 90 deletions.
3 changes: 0 additions & 3 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ import { RouterProvider } from "react-router-dom";

// Internal imports
import router from "router/Router";
import { HeaderNav, FooterNav } from "components/components";

export default function App() {
return (
<>
<HeaderNav />
<RouterProvider router={router} />
<FooterNav />
</>
);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions frontend/src/components/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Checkbox } from "./Inputs/Checkbox";
import { Chip } from "./Inputs/Chip";
import { Dropdown, DropdownOption } from "./Inputs/Dropdown";
import { TextField } from "./Inputs/Textfield";
import { HeaderNav } from "./Navigation/HeaderNav";
import { FooterNav } from "./Navigation/FooterNav";
import { ProgressBar } from "./Navigation/ProgressBar";
import { Notification } from "./Notification/Notification";
Expand All @@ -36,7 +35,6 @@ export {
DropdownOption,
TextField,
// Navigation
HeaderNav,
FooterNav,
ProgressBar,
// Notification
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/layouts/DefaultNavLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from "react";
import { Outlet } from "react-router-dom";
import { FooterNav } from "components/components";
import { HeaderNav } from "tw-components";

const DefaultNavLayout = () => {
return (
<>
<HeaderNav />
<Outlet />
<FooterNav />
</>
);
};

export default DefaultNavLayout;
12 changes: 12 additions & 0 deletions frontend/src/layouts/HomeLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";
import { Outlet } from "react-router-dom";

const HomeLayout = () => {
return (
<>
<Outlet />
</>
);
};

export default HomeLayout;
33 changes: 17 additions & 16 deletions frontend/src/pages/Authentication/page.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
import React from "react";
import { Link, useLocation } from "react-router-dom";

import InputGroup from "../../tw-components/InputGroup";
import { AuthNav, InputGroup } from "tw-components";

/** AuthenticationPage
* @dev handles both "/login" and "/signup" paths
* @dev shows the <LoginForm /> or <SignupForm /> depending on the path
*/
*/

export default function AuthenticationPage() {
return (
<div className="flex flex-row" style={{ height: "calc(100vh - 64px)" }}>
<div className="w-full lg:basis-1/2 bg-tan">
<div className="lg:hidden flex flex-col justify-center items-center h-full">
<div className="w-10/12">
<div className="bg-white p-3 rounded-2xl">
<AuthForm />
<>
<AuthNav />
<div className="flex flex-row" style={{ height: "calc(100vh - 64px)" }}>
<div className="w-full lg:basis-1/2 bg-tan">
<div className="lg:hidden flex flex-col justify-center items-center h-full">
<div className="w-10/12">
<div className="bg-white p-3 rounded-2xl">
<AuthForm />
</div>
</div>
</div>
</div>
</div>
<div className="max-lg:hidden basis-1/2">
<div className="flex flex-col justify-center items-center h-full">
<div className="w-[439px]">
<AuthForm />
<div className="max-lg:hidden basis-1/2">
<div className="flex flex-col justify-center items-center h-full">
<div className="w-[439px]">
<AuthForm />
</div>
</div>
</div>
</div>
</div>
</>
);
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/CreditsPage/CreditsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import React, { Fragment, useState } from "react";
import { logoHfLA } from "assets/images/images";
import { Chip } from "components/components";
import { Card } from "components/Cards/StandardCard";
import { iconData } from "pages/api_data/creditsIconData";
import { illustrationData } from "pages/api_data/creditsIllustrationData";
import { iconData } from "api_data/creditsIconData";
import { illustrationData } from "api_data/creditsIllustrationData";

const CreditsPage = () => {
const [activeData, setActiveData] = useState(illustrationData);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/LandingPage/LandingPageCop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
copDatum,
fetchAllCopData,
fetchCopDataById,
} from "../api_data/copData";
} from "../../api_data/copData";

function LandingPageCop() {
const [isDialogOpen, setIsDialogOpen] = useState(false);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/QualifierPage/QualifierPageCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Button,
} from "components/components";
import { QualifierNav, QualifierTitle } from "./QualifierComponents";
import { timezones } from "../api_data/timezoneData";
import { timezones } from "../../api_data/timezoneData";
import { iconArrowLeft } from "assets/images/images";

function QualifierPageCalendar() {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/QualifierPage/QualifierPageRoles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useNavigate } from "react-router-dom";
// Internal Imports
import { Button, Chip } from "components/components";
import { QualifierNav, QualifierTitle } from "./QualifierComponents";
import { fetchAllCopData, copDatum } from "pages/api_data/copData";
import { fetchAllCopData, copDatum } from "api_data/copData";
import { onKey } from "components/Utility/utils";

function QualifierPageRoles() {
Expand Down
83 changes: 57 additions & 26 deletions frontend/src/router/Router.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// External Imports
import React, { Fragment } from "react";
import {
createRoutesFromElements,
createBrowserRouter,
Route,
} from "react-router-dom";
import React from "react";
import { createBrowserRouter } from "react-router-dom";

// Internal Imports
import { CreditsPage } from "pages/CreditsPage/CreditsPage";
Expand All @@ -18,26 +14,61 @@ import {
loader as qualifierLoader,
} from "pages/QualifierPage/QualifierPage";
import AuthenticationPage from "pages/Authentication/page";
import HomeLayout from "layouts/HomeLayout";
import DefaultNavLayout from "layouts/DefaultNavLayout";

const router = createBrowserRouter(
createRoutesFromElements(
<Fragment>
<Route path="/" element={<LandingPage />} />
<Route path="/login" element={<AuthenticationPage />} />
<Route path="/signup" element={<AuthenticationPage />} />
<Route path="qualifier/" element={<QualifierPage />}>
<Route
path=":page/"
element={<QualifierContent />}
loader={qualifierLoader}
/>
</Route>
<Route path="/demo" element={<Demo />} />
<Route path="/demo-tailwind" element={<DemoTailwind />} />
<Route path="/credits" element={<CreditsPage />} />
<Route path="*" element={<NotFoundPage />} />
</Fragment>
)
);
const router = createBrowserRouter([
{
path: "/",
element: <HomeLayout />,
children: [
{
path: "/",
element: <DefaultNavLayout />,
children: [
{
index: true,
element: <LandingPage />,
},
{
path: "qualifier",
element: <QualifierPage />,
children: [
{
path: ":page",
element: <QualifierContent />,
loader: qualifierLoader,
},
],
},
{
path: "credits",
element: <CreditsPage />,
},
{
path: "demo",
element: <Demo />,
},
{
path: "demo-tailwind",
element: <DemoTailwind />,
},
{
path: "*",
element: <NotFoundPage />,
},
],
},
],
},
{
path: "login",
element: <AuthenticationPage />,
},
{
path: "signup",
element: <AuthenticationPage />,
},
]);

export default router;
38 changes: 38 additions & 0 deletions frontend/src/tw-components/AuthNav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// External Imports
import React, { useState } from "react";

// Internal Imports
import { logoHorizontal } from "assets/images/images";
import { iconArrowLeft } from "assets/images/images";

function AuthNav() {
const [path] = useState(window.location.pathname);

const Logo = () => {
return (
<a href="/" rel="noopener noreferrer">
<img
className="max-h-[24px] md:max-h-[32px]"
src={logoHorizontal}
alt="Civic Tech Jobs - Home"
/>
</a>
);
};

return (
<header className="h-16 py-1 px-3 w-full flex items-center justify-center shadow-[-1px_1px_2px_rgb(51,51,51,0.2)]">
<div className="grow flex justify-center">
<a href="/">
<img src={iconArrowLeft} alt="Back to home arrow" className="w-5" />
</a>
</div>
<div>
<Logo />
</div>
<div className="grow"></div>
</header>
);
}

export default AuthNav;
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// External Imports
import React, { Fragment, useState } from "react";
import React from "react";

// Internal Imports
import { logoHorizontal, logoStacked } from "assets/images/images";
import { logoHorizontal } from "assets/images/images";
import { IconHamburgerMenu } from "assets/images/images";
import { Button } from "../Buttons/Button";
import { iconArrowLeft } from "assets/images/images";
import { Button } from "../components/components";
import { Link } from "react-router-dom";

interface menuObject {
name?: string;
Expand All @@ -21,15 +21,7 @@ const menuItems: menuObject[] = [
{ name: "Projects", link: "https://www.hackforla.org/projects/" },
];

/** HeaderNav component
* @dev changes from default to auth header depending on the path
* @dev can't use the Link component from react router because this component
* is rendered outside of the router context created in Router.tsx
*/

function HeaderNav() {
const [path] = useState(window.location.pathname);

const Logo = () => {
return (
<a href="/" rel="noopener noreferrer">
Expand All @@ -42,7 +34,7 @@ function HeaderNav() {
);
};

const DefaultHeader = (
return (
<header className="h-16 py-1 px-3 w-full flex items-center justify-between shadow-[-1px_1px_2px_rgb(51,51,51,0.2)]">
<div>
<Logo />
Expand All @@ -67,9 +59,11 @@ function HeaderNav() {
})}
</nav>

<Button href="/login" color="primary" size="sm">
Log In
</Button>
<Link to="/login">
<Button color="primary" size="sm">
Log In
</Button>
</Link>
<button
className="md:hidden ml-3"
aria-expanded="false"
Expand All @@ -80,26 +74,6 @@ function HeaderNav() {
</div>
</header>
);

const AuthHeader = (
<header className="h-16 py-1 px-3 w-full flex items-center justify-center shadow-[-1px_1px_2px_rgb(51,51,51,0.2)]">
<div className="grow flex justify-center">
<a href="/">
<img src={iconArrowLeft} alt="Back to home arrow" className="w-5" />
</a>
</div>
<div>
<Logo />
</div>
<div className="grow"></div>
</header>
);

if (path === "/login" || path === "/signup") {
return AuthHeader;
} else {
return DefaultHeader;
}
}

export { HeaderNav };
export default HeaderNav;
3 changes: 3 additions & 0 deletions frontend/src/tw-components/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as AuthNav } from "./AuthNav";
export { default as HeaderNav } from "./HeaderNav";
export { default as InputGroup } from "./InputGroup";
1 change: 0 additions & 1 deletion frontend/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module.exports = {
content: [
"./src/pages/Demo/DemoTailwind.tsx",
"./src/pages/Authentication/*.tsx",
"./src/components/Navigation/HeaderNav.tsx",
"./src/tw-components/*.tsx",
], // Will change to "./src/**/*.{js,jsx,tsx}", "./templates/index.html"
theme: {
Expand Down

0 comments on commit 8b75cfb

Please sign in to comment.