Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add breadcrumbs #268

Merged
merged 6 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
55 changes: 55 additions & 0 deletions src/components/breadcrumbs/BreadcrumbsNav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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";

type Student = SelectableForTable<"student">;
type Para = SelectableForTable<"user">;

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

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

const personData: Student | Para | undefined = student || para;

// 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these conditionals are good for now - once we get more path links, like STUDENTS / Student Name / Goal / Benchmark (for data visualization), like you say in the documentation/comments, we can add for those cases
.

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;
92 changes: 45 additions & 47 deletions src/components/navbar/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useRouter } from "next/router";
import * as React from "react";
import { MouseEventHandler } from "react";
import $navbar from "./Navbar.module.css";
import BreadcrumbsNav from "../breadcrumbs/BreadcrumbsNav";

interface NavItemProps {
href?: string;
Expand Down Expand Up @@ -57,9 +58,8 @@ export default function NavBar() {
<IconButton
color="inherit"
aria-label="open drawer"
edge="start"
onClick={handleDrawerToggle}
sx={{ mr: 2, display: desktop ? "none" : "" }}
sx={{ mr: 2 }}
>
{name}
</IconButton>
Expand Down Expand Up @@ -87,7 +87,7 @@ export default function NavBar() {
};

const drawer = (
<div className={$navbar.sidebar}>
<div className={$navbar.navbarDropdown}>
<List>
<NavItem href="/students" icon={<PeopleOutline />} text="Students" />
<NavItem href="/staff" icon={<CoPresent />} text="Staff" />
Expand All @@ -105,51 +105,49 @@ export default function NavBar() {
<>
{status === "authenticated" && (
<Box sx={{ display: "flex" }}>
{/* Sidebar for screens > md size */}
<Box
component="nav"
aria-label="nav"
className={$navbar.sidebar}
sx={{
display: desktop ? "block" : "none",
width: "200px",
}}
>
{logo}
{drawer}
</Box>
{desktop ? (
<>
{/* Sidebar for screens & breadcrumbs > md size */}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good comment/documentation

<Box component="nav" aria-label="nav" className={$navbar.sidebar}>
{logo}
{drawer}
</Box>
<BreadcrumbsNav />
</>
) : (
<>
{/* Top nav for screen <= md size */}
<AppBar position="fixed" sx={{ display: "block" }}>
<ToolbarMenu
name={
<MenuIcon className={$navbar.burger} fontSize="large" />
}
/>
</AppBar>

{/* Top nav for screen <= md size */}
<AppBar
position="fixed"
sx={{
display: desktop ? "none" : "block",
}}
>
<ToolbarMenu
name={<MenuIcon className={$navbar.burger} fontSize="large" />}
/>
</AppBar>

{/* Modal for sidebar when screen is <= md size */}
<Drawer
variant="temporary"
anchor="top"
open={mobileOpen}
onClick={handleDrawerToggle}
sx={{
display: desktop ? "none" : "block",
"& .MuiDrawer-paper": {
boxSizing: "border-box",
width: "full",
},
}}
>
<ToolbarMenu
name={<CloseIcon className={$navbar.burger} fontSize="large" />}
/>
{drawer}
</Drawer>
{/* Modal for sidebar when screen is <= md size */}
<Drawer
variant="temporary"
anchor="top"
open={mobileOpen}
onClick={handleDrawerToggle}
sx={{
display: "block",
"& .MuiDrawer-paper": {
boxSizing: "border-box",
width: "full",
},
}}
>
<ToolbarMenu
name={
<CloseIcon className={$navbar.burger} fontSize="large" />
}
/>
{drawer}
</Drawer>
</>
)}
</Box>
)}
</>
Expand Down
7 changes: 7 additions & 0 deletions src/components/navbar/Navbar.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
display: flex;
justify-content: space-between;
box-shadow: 0;
padding: 0;
}

.navbarDropdown {
background-color: var(--primary-40);
}

.sidebar {
background-color: var(--primary-40);
display: block;
width: 200px;
}

.link {
Expand Down
Loading