Skip to content

Commit

Permalink
Incorporate MUI breadcrumbs into file. Rename Breadcrumbs to Breadcru…
Browse files Browse the repository at this point in the history
…mbsNav. Extract CSS to its own file.
  • Loading branch information
hieungo89 committed Nov 22, 2023
1 parent 3b8f4d4 commit 37a06a8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 58 deletions.
18 changes: 18 additions & 0 deletions src/components/breadcrumbs/Breadcrumbs.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.container {
position: fixed;
display: flex;
left: 200px;
z-index: 1;
padding: 1rem 0 1rem 2rem;
width: 100%;
background-color: var(--grey-100);
}

.link {
text-decoration: none;
color: var(--grey-10);
}

.link:hover {
text-decoration: underline;
}
60 changes: 60 additions & 0 deletions src/components/breadcrumbs/BreadcrumbsNav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { trpc } from "@/client/lib/trpc";
import Breadcrumbs from "@mui/material/Breadcrumbs";
import Link from "next/link";
import { useRouter } from "next/router";
import { SelectableForTable } from "zapatos/schema";
import $breadcrumbs from "./Breadcrumbs.module.css";

const BreadcrumbsNav = () => {
const router = useRouter();
const paths = router.asPath.split("/");

let personData:
| SelectableForTable<"student">
| SelectableForTable<"user">
| undefined;

if (paths[1] === "students" && paths[2]) {
const { data } = trpc.student.getStudentById.useQuery(
{ student_id: paths[2] },
{ enabled: Boolean(paths[2]), retry: false }
);
personData = data;
} else if (paths[1] === "staff" && paths[2]) {
const { data } = trpc.para.getParaById.useQuery(
{ user_id: paths[2] },
{ enabled: Boolean(paths[2]), retry: false }
);
personData = data;
}

// An array of breadcrumbs fixed to students/staff as the first index. This will be modified depending on how the address bar will be displayed.
const breadcrumbs = paths.map((path, index) => {
if (index === 0) return "";
if (index % 2 === 1) {
return (
<Link key={index} href={`/${path}`} className={$breadcrumbs.link}>
{path.toUpperCase()}
</Link>
);
}
if (index === 2) {
return (
<div key={index} style={{ color: "var(--grey-10)" }}>
{personData?.first_name} {personData?.last_name}
</div>
);
}
return <div key={index}>{path}</div>;
});

return (
<div className={$breadcrumbs.container}>
<Breadcrumbs separator="/" aria-label="breadcrumb">
{breadcrumbs}
</Breadcrumbs>
</div>
);
};

export default BreadcrumbsNav;
56 changes: 0 additions & 56 deletions src/components/breadcrumbs/breadcrumbs.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/components/navbar/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useRouter } from "next/router";
import * as React from "react";
import { MouseEventHandler } from "react";
import $navbar from "./Navbar.module.css";
import Breadcrumbs from "../breadcrumbs/breadcrumbs";
import BreadcrumbsNav from "../breadcrumbs/BreadcrumbsNav";

interface NavItemProps {
href?: string;
Expand Down Expand Up @@ -112,7 +112,7 @@ export default function NavBar() {
{logo}
{drawer}
</Box>
<Breadcrumbs />
<BreadcrumbsNav />
</>
) : (
<>
Expand Down

0 comments on commit 37a06a8

Please sign in to comment.