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 header #4

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
55 changes: 55 additions & 0 deletions apps/nextjs/src/app/_components/header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Link from "next/link";

import { auth, signIn, signOut } from "@acme/auth";
import { Button } from "@acme/ui/button";

const sharedClasses = {
Copy link
Owner

Choose a reason for hiding this comment

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

FYI: I think this is a tailwind antipattern.
I'm unsure if lsp and formatting will handle this correctly

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The shared classes? I agree 100%, I think this was me experimenting with Co-pilot and wanted it to improve my code but it rather made an anti-pattern, can be changed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, close if you are satisfied

navContainer:
"mx-auto flex items-left md:justify-center p-6 lg:px-8 shadow-lg",
linkContainer: "md:flex lg:flex-1 space-x-4 pr-4",
button: "text-sm font-semibold leading-6",
hiddenLgFlex: "min-[320px]:px-4 sm:px-4 md:flex md:justify-end",
hiddenLgFlex1: "min-[320px]:px-4 sm:px-4 md:flex md:flex-1 md:justify-end",
};

export default async function Header() {
const session = await auth();
const user = session?.user;
return (
<header className="w-full bg-primary text-primary-foreground shadow-md">
<nav className={sharedClasses.navContainer}>
<div className={sharedClasses.linkContainer}>
<Link href="/">Home</Link>
</div>
{user ? (
<div className="flex items-center">
<p className="m-3 text-sm">Logged in as {user.name}</p>
<form>
<Button
size="lg"
formAction={async () => {
"use server";
await signOut();
}}
>
Log out
</Button>
</form>
</div>
) : (
<form className={sharedClasses.hiddenLgFlex1}>
<Button
size="lg"
formAction={async () => {
"use server";
await signIn();
}}
>
Sign in
</Button>
</form>
)}
</nav>
</header>
);
}
9 changes: 6 additions & 3 deletions apps/nextjs/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ import { TRPCReactProvider } from "~/trpc/react";
import "~/app/globals.css";

import { env } from "~/env";
import Header from "./_components/header";

const PRODUCTION_DOMAINE =
const PRODUCTION_DOMAIN =
"https://shared-expensesnext-js-gnrsns-projects.vercel.app";

export const metadata: Metadata = {
metadataBase: new URL(
env.VERCEL_ENV === "production"
? PRODUCTION_DOMAINE
? PRODUCTION_DOMAIN
: "http://localhost:3000",
),
title: "Shared expenses",
description: "",
openGraph: {
title: "Shared expenses",
description: "",
url: PRODUCTION_DOMAINE,
url: PRODUCTION_DOMAIN,
siteName: "Shared expenses",
},
};
Expand All @@ -49,6 +50,8 @@ export default function RootLayout(props: { children: React.ReactNode }) {
)}
>
<ThemeProvider attribute="class" defaultTheme="light" enableSystem>
<Header />

<TRPCReactProvider>{props.children}</TRPCReactProvider>
<div className="absolute bottom-4 right-4">
<ThemeToggle />
Expand Down
Loading