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

Navbar now gets user from context instead of props #49

Merged
merged 4 commits into from
Aug 16, 2023
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
11 changes: 7 additions & 4 deletions src/app/admin/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { authOptions } from "@/shared/auth";
import Navbar from "@/components/Navbar";

import { fetchUserWithSession } from "@/shared/auth";
import { UserProvider } from "@/contexts/UserProvider";

export const metadata: Metadata = {
title: "PodCodar Admin",
Expand All @@ -19,10 +20,12 @@ export default async function RootLayout({ children }: PropsWithChildren) {
return (
<body>
<AuthProvider>
<div className="bg-white shadow">
<Navbar loggedUser={loggedUser} />
</div>
{children}
<UserProvider user={loggedUser}>
<div className="bg-white shadow">
<Navbar />
</div>
{children}
</UserProvider>
</AuthProvider>
</body>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default async function RootLayout({ children }: PropsWithChildren) {
<AuthProvider>
<UserProvider user={loggedUser}>
<div className="shadow-md">
<Navbar loggedUser={loggedUser} />
<Navbar />
</div>
{children}
</UserProvider>
Expand Down
9 changes: 3 additions & 6 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ import { Bars3Icon, BellIcon, XMarkIcon } from "@heroicons/react/24/outline";
import { Logo } from "./Logo";
import { classes } from "@/shared/tw";
import Image from "next/image";
import { User } from "@prisma/client";
import Link from "next/link";
import { useUser } from "@/contexts/UserProvider";

const navigation = [{ name: "Home", href: "/app", current: true }];

const profileLinks = [{ name: "Sign out", onClick: () => signOut() }];

type Props = {
loggedUser: User;
};

export default function Navbar({ loggedUser }: Props) {
export default function Navbar() {
const loggedUser = useUser();
return (
<Disclosure as="nav" className="bg-gray-800">
{({ open }) => (
Expand Down