Skip to content

Commit

Permalink
Dynamic page title
Browse files Browse the repository at this point in the history
  • Loading branch information
Zynthasius39 committed Jan 10, 2025
1 parent 1dbf721 commit 71dbcad
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 43 deletions.
33 changes: 31 additions & 2 deletions src/Components.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import { Button, styled, Switch, SwitchProps } from "@mui/material";
import { Button, styled, Switch } from "@mui/material";
import {
AnnouncementTwoTone,
ArticleTwoTone,
CalendarMonthTwoTone,
DashboardTwoTone,
DoorSlidingTwoTone,
FolderTwoTone,
GradeTwoTone,
GradingTwoTone,
SettingsTwoTone,
SummarizeTwoTone,
} from "@mui/icons-material";

export const MaterialUISwitch = styled(Switch)(({ theme }) => ({
width: 62,
Expand Down Expand Up @@ -125,4 +137,21 @@ export const PrimaryButton = styled(Button, {
":disabled": {
backgroundColor: theme.palette.primaryButton.dark,
}
}));
}));

export const spMenu = [
{ name: "Dashboard", icon: <DashboardTwoTone color="primary" />, href: "/" },
{
name: "Announces",
icon: <AnnouncementTwoTone color="primary" />,
href: "/announces",
},
{ name: "Departments", icon: <FolderTwoTone color="primary" />, href: "" },
{ name: "Course", icon: <CalendarMonthTwoTone color="primary" />, href: "" },
{ name: "Grades", icon: <GradeTwoTone color="primary" />, href: "/grades" },
{ name: "Transcript", icon: <SummarizeTwoTone color="primary" />, href: "" },
{ name: "Attendance", icon: <GradingTwoTone color="primary" />, href: "" },
{ name: "Gate", icon: <DoorSlidingTwoTone color="primary" />, href: "" },
{ name: "Documents", icon: <ArticleTwoTone color="primary" />, href: "" },
{ name: "Settings", icon: <SettingsTwoTone color="primary" />, href: "" },
];
17 changes: 12 additions & 5 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { Box, Stack } from "@mui/material";
import Navbar from "./Navbar";
import { Outlet, useNavigate } from "react-router-dom";
import { Outlet, useLocation, useNavigate } from "react-router-dom";
import DrawerList from "./DrawerList";
import { useTheme } from "../utils/Theme";
import { useAuth } from "../utils/Auth";
import { verify } from "../utils/Api";
import { spMenu } from "../Components";

export default function App() {
const { authed, imageURL, name, logout, verifiedAuth } = useAuth();
const { theme } = useTheme();
const navigate = useNavigate();
const [page] = useState("Dashboard");
const [page, setPage] = useState("Dashboard");
const path = useLocation();

const getComponent = async () => {
if (!await verify()) {
Expand All @@ -22,11 +24,16 @@ export default function App() {
}
}

const updatePage = () => {
setPage(spMenu.find(m => m.href === path.pathname)?.name || "");
}

useEffect(() => {
updatePage();
if (!authed) {
getComponent();
}
}, [name, imageURL]);
}, [name, imageURL, path]);

return (
<Stack
Expand All @@ -45,7 +52,7 @@ export default function App() {
<DrawerList />
</Box>
<Stack flex={4} bgcolor="background.default" color="text.primary">
<Navbar name={name} page={page} />
<Navbar name={name} page={page}/>
<Box p={1} flex={8} overflow="auto">
<Outlet />
</Box>
Expand Down
37 changes: 2 additions & 35 deletions src/components/DrawerList.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
import {
AnnouncementTwoTone,
ArticleTwoTone,
CalendarMonthTwoTone,
DashboardTwoTone,
DoorSlidingTwoTone,
FolderTwoTone,
GradeTwoTone,
GradingTwoTone,
LogoutTwoTone,
SettingsTwoTone,
SummarizeTwoTone,
} from "@mui/icons-material";
import {
Stack,
List,
Expand All @@ -20,30 +7,14 @@ import {
Divider,
ListItemIcon,
Box,
Avatar,
} from "@mui/material";
import logo_dark from "../assets/beu_dark.svg";
import { NavLink, useLocation, useNavigate } from "react-router-dom";
import { useTheme } from "../utils/Theme";
import { useCallback } from "react";
import { useAuth } from "../utils/Auth";

const spMenu = [
{ name: "Dashboard", icon: <DashboardTwoTone color="primary" />, href: "/" },
{
name: "Announces",
icon: <AnnouncementTwoTone color="primary" />,
href: "/announces",
},
{ name: "Departments", icon: <FolderTwoTone color="primary" />, href: "" },
{ name: "Course", icon: <CalendarMonthTwoTone color="primary" />, href: "" },
{ name: "Grades", icon: <GradeTwoTone color="primary" />, href: "/grades" },
{ name: "Transcript", icon: <SummarizeTwoTone color="primary" />, href: "" },
{ name: "Attendance", icon: <GradingTwoTone color="primary" />, href: "" },
{ name: "Gate", icon: <DoorSlidingTwoTone color="primary" />, href: "" },
{ name: "Documents", icon: <ArticleTwoTone color="primary" />, href: "" },
{ name: "Settings", icon: <SettingsTwoTone color="primary" />, href: "" },
];
import { spMenu } from "../Components";
import { LogoutTwoTone } from "@mui/icons-material";

const DrawerList = () => {
const { logout, setImage } = useAuth();
Expand Down Expand Up @@ -120,9 +91,7 @@ const DrawerList = () => {
}}
>
<ListItemIcon>
{/* <Avatar sx={{ backgroundColor: theme.palette.primary.dark }}> */}
{icon}
{/* </Avatar> */}
</ListItemIcon>
<Typography>{name}</Typography>
</ListItemButton>
Expand All @@ -132,9 +101,7 @@ const DrawerList = () => {
<Link href="" color="inherit" underline="none" width={"100%"}>
<ListItemButton key="logout" sx={{ p: "5%", pl: "10%" }} onClick={handleLogout}>
<ListItemIcon>
{/* <Avatar sx={{ backgroundColor: theme.palette.primary.dark }}> */}
<LogoutTwoTone color="primary" />
{/* </Avatar> */}
</ListItemIcon>
<Typography fontSize={14}>LogOut</Typography>
</ListItemButton>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const Navbar = (props: { name: string; page: string }) => {
{props.page}
</Typography>
<MaterialUISwitch
sx={{ m: "2dvw", display: {
sx={{ m: 1, display: {
xs: "none",
sm: "inherit",
} }}
Expand Down

0 comments on commit 71dbcad

Please sign in to comment.