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

refactor: make drawer component #189

Merged
merged 7 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/components/Applicant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ const ApplicationPopupButton = ({
return (
<>
<Button variant="outline" onClick={() => setVisibility(true)}>
View Application
View
</Button>
{isVisible && (
<>
Expand Down
111 changes: 111 additions & 0 deletions src/components/Drawer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import ThemeToggle from "./ThemeToggle";
import { signOut, useSession } from "next-auth/react";
import Background from "./Background";
import { useRef } from "react";
import { useRouter } from "next/router";
import NavBar from "./NavBar";
import Link from "next/link";

interface PageTab {
pageName: string;
link: string;
}

export const Drawer = ({
children,
pageTabs,
}: {
children: JSX.Element[] | JSX.Element;
pageTabs?: PageTab[];
}) => {
const { data: session } = useSession();
const router = useRouter();

const drawer = useRef<HTMLInputElement>(null);

return (
<>
<Background />
<div className="drawer drawer-end relative h-full min-h-screen w-full overflow-x-hidden font-montserrat">
<input
id="my-drawer-3"
type="checkbox"
className="drawer-toggle"
ref={drawer}
/>

<div className="drawer-content flex flex-col">
<NavBar />
{children}
</div>

<div className="drawer-side md:hidden z-50 ">
<label
htmlFor="my-drawer-3"
className="drawer-overlay md:hidden"
></label>

<div className="menu h-full w-80 flex-row content-between overflow-y-auto bg-white p-4 dark:bg-[#1F1F1F] md:hidden">
<ul className="w-full">
<button
className="btn btn-square btn-ghost drawer-button"
onClick={() => {
if (drawer.current) {
drawer.current.checked = false;
}
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
>
<path
fill="currentColor"
fillRule="evenodd"
d="m6.5 17.5l8.25-5.5L6.5 6.5l1-1.5L18 12L7.5 19z"
/>
</svg>
</button>
{pageTabs?.map(({ pageName, link }, i) => (
<li key={i}>
<Link className="mx-2 my-2 text-base font-bold" href={link}>
{pageName}
</Link>
</li>
))}
</ul>

<div className="mx-1 mb-2 flex w-full items-center justify-between ">
<ThemeToggle />
{session ? (
<div>
<a className="font-sub mx-2.5 text-sm">
Hi,{" "}
<strong className="font-bold">{session?.user?.name}</strong>
</a>
<button
onClick={() => signOut()}
className="font-sub rounded bg-primary px-2.5 py-2.5 text-sm font-bold text-white dark:text-gray-300"
>
Sign Out
</button>
</div>
) : (
<button
className="btn btn-primary text-white"
onClick={() => router.push("/login")}
>
Sign In
</button>
)}
</div>
</div>
</div>
</div>
</>
);
};

export default Drawer;
Comment on lines +14 to +111
Copy link
Contributor

Choose a reason for hiding this comment

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

Well-structured Drawer component with effective use of React features.

The component is well-structured, making good use of React hooks, refs, and conditional rendering. The use of useSession for session management and useRouter for navigation is appropriate. The ref usage for controlling the drawer's state is a good practice.

Suggestion for Improvement:
Consider adding aria-labels to interactive elements like buttons for better accessibility.

7 changes: 0 additions & 7 deletions src/components/GradingBackground.tsx

This file was deleted.

69 changes: 0 additions & 69 deletions src/components/GradingNavBar.tsx

This file was deleted.

87 changes: 0 additions & 87 deletions src/components/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import Link from "next/link";
import ThemeToggle from "./ThemeToggle";
import { signOut, useSession } from "next-auth/react";
import Background from "./Background";
import { useRef } from "react";
import { useRouter } from "next/router";
import { router } from "../server/router/trpc";

const NavBar = () => {
const { data: session } = useSession();
Expand Down Expand Up @@ -78,88 +75,4 @@ const NavBar = () => {
);
};

export const Drawer = ({
children,
}: {
children: JSX.Element[] | JSX.Element;
}) => {
const { data: session } = useSession();
const router = useRouter();

const drawer = useRef<HTMLInputElement>(null);

return (
<>
<Background />
<div className="drawer drawer-end relative h-full w-full overflow-x-hidden font-montserrat">
<input
id="my-drawer-3"
type="checkbox"
className="drawer-toggle"
ref={drawer}
/>

<div className="drawer-content flex flex-col">
<NavBar />
{children}
</div>
<div className="drawer-side md:hidden z-50 ">
<label
htmlFor="my-drawer-3"
className="drawer-overlay md:hidden"
></label>
<div className="menu h-full w-80 flex-row content-between overflow-y-auto bg-white p-4 dark:bg-[#1F1F1F] md:hidden">
<button
className="btn btn-square btn-ghost drawer-button"
onClick={() => {
if (drawer.current) {
drawer.current.checked = false;
}
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
>
<path
fill="currentColor"
fillRule="evenodd"
d="m6.5 17.5l8.25-5.5L6.5 6.5l1-1.5L18 12L7.5 19z"
/>
</svg>
</button>

<div className="mx-1 mb-2 flex w-full items-center justify-between ">
<ThemeToggle />
{session ? (
<div>
<a className="font-sub mx-2.5 text-sm">
Hi,{" "}
<strong className="font-bold">{session?.user?.name}</strong>
</a>
<button
onClick={() => signOut()}
className="font-sub rounded bg-primary px-2.5 py-2.5 text-sm font-bold text-white dark:text-gray-300"
>
Sign Out
</button>
</div>
) : (
<button
className="btn btn-primary text-white"
onClick={() => router.push("/login")}
>
Sign In
</button>
)}
</div>
</div>
</div>
</div>
</>
);
};

export default NavBar;
62 changes: 0 additions & 62 deletions src/components/navigation.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/pages/apply.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import useFormPersist from "react-hook-form-persist";
import { getServerAuthSession } from "../server/common/get-server-auth-session";
import { prisma } from "../server/db/client";
import { trpc } from "../utils/trpc";
import { Drawer } from "../components/NavBar";
import Drawer from "../components/Drawer";
import applicationSchema from "../schemas/application";
import CustomSelect from "../components/CustomSelect";
import FormDivider from "../components/FormDivider";
Expand Down
Loading
Loading