Skip to content

Commit a87fa2f

Browse files
committed
added nav drawer
1 parent 69a1f8d commit a87fa2f

File tree

1 file changed

+50
-4
lines changed

1 file changed

+50
-4
lines changed

app/root.tsx

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ import {
88
Outlet,
99
Scripts,
1010
ScrollRestoration,
11+
Link,
12+
Form,
13+
useLoaderData,
1114
} from "@remix-run/react";
1215

1316
import { getUser } from "~/session.server";
1417
import stylesheet from "~/tailwind.css";
18+
import React, { useState } from 'react'; // Import React and useState
1519

1620
export const links: LinksFunction = () => [
1721
{ rel: "stylesheet", href: stylesheet },
@@ -23,6 +27,10 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
2327
};
2428

2529
export default function App() {
30+
const [drawerOpen, setDrawerOpen] = useState(false); // State for drawer
31+
const data = useLoaderData<typeof loader>();
32+
const user = data.user;
33+
2634
return (
2735
<html lang="en" className="h-full">
2836
<head>
@@ -32,10 +40,48 @@ export default function App() {
3240
<Links />
3341
</head>
3442
<body className="h-full">
35-
<Outlet />
36-
<ScrollRestoration />
37-
<Scripts />
38-
<LiveReload />
43+
<header className="flex items-center justify-between bg-slate-800 p-4 text-white">
44+
<div className="flex items-center">
45+
<button onClick={() => setDrawerOpen(!drawerOpen)} className="text-white hover:text-gray-300 focus:outline-none mr-4">
46+
<svg className="h-6 w-6 fill-current" viewBox="0 0 24 24">
47+
<path fillRule="evenodd" d="M4 5h16a1 1 0 0 1 0 2H4a1 1 0 1 1 0-2zm0 6h16a1 1 0 0 1 0 2H4a1 1 0 1 1 0-2zm0 6h16a1 1 0 0 1 0 2H4a1 1 0 1 1 0-2z" clipRule="evenodd" />
48+
</svg>
49+
</button>
50+
<h1 className="text-3xl font-bold">
51+
<Link to="/">Home</Link>
52+
</h1>
53+
</div>
54+
<div className="flex items-center">
55+
<p className="mr-4">{user?.email}</p>
56+
<Form action="/logout" method="post">
57+
<button
58+
type="submit"
59+
className="rounded bg-slate-600 px-4 py-2 text-blue-100 hover:bg-blue-500 active:bg-blue-600"
60+
>
61+
Logout
62+
</button>
63+
</Form>
64+
</div>
65+
</header>
66+
<div className={`fixed top-0 left-0 h-full w-64 bg-white shadow-md p-4 ${drawerOpen ? 'translate-x-0' : '-translate-x-full'} transition-transform duration-300 z-50`}>
67+
<button onClick={() => setDrawerOpen(false)} className="absolute top-2 right-2 text-gray-500 hover:text-gray-800 focus:outline-none">
68+
<svg className="h-6 w-6 fill-current" viewBox="0 0 24 24">
69+
<path fill="currentColor" d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/>
70+
</svg>
71+
</button>
72+
<h2 className="font-bold mb-4">Navigation</h2>
73+
<ul>
74+
<li className="mb-2"><Link to="/portal" className="block py-2 px-4 hover:bg-gray-100" onClick={() => setDrawerOpen(false)}>Portal</Link></li>
75+
<li className="mb-2"><Link to="/bible" className="block py-2 px-4 hover:bg-gray-100" onClick={() => setDrawerOpen(false)}>Bible</Link></li>
76+
<li className="mb-2"><Link to="/notes" className="block py-2 px-4 hover:bg-gray-100" onClick={() => setDrawerOpen(false)}>Notes</Link></li>
77+
</ul>
78+
</div>
79+
<div className="ml-0 transition-margin duration-300" style={{ marginLeft: drawerOpen ? '64px' : '0' }}>
80+
<Outlet />
81+
<ScrollRestoration />
82+
<Scripts />
83+
<LiveReload />
84+
</div>
3985
</body>
4086
</html>
4187
);

0 commit comments

Comments
 (0)