Skip to content

Commit

Permalink
Clean up navbar code, add logout button
Browse files Browse the repository at this point in the history
  • Loading branch information
sigridge committed Oct 16, 2023
1 parent 02096fb commit 095dc4d
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 248 deletions.
5 changes: 3 additions & 2 deletions frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "./globals.css";
import Head from "next/head";
import AppProviders from "../components/AppProviders";
import NavBar from "@/components/NavBar";

export default function RootLayout({
children,
Expand All @@ -17,7 +17,8 @@ export default function RootLayout({
/>
</Head>
<body>
<AppProviders>{children}</AppProviders>
<NavBar />
{children}
</body>
</html>
);
Expand Down
17 changes: 0 additions & 17 deletions frontend/src/components/AppProviders.tsx

This file was deleted.

23 changes: 23 additions & 0 deletions frontend/src/components/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Image from "next/image";
import NavBarLink from "./NavBarLink";
import NavBarUserIcon from "./NavBarUserIcon";

export default async function NavBar() {
return (
<div className="bg-primary_default w-full h-[52px] flex flex-row justify-between sticky top-0 px-4">
<div className="flex flex-row">
<NavBarLink text="Bemanning" path="/bemanning" />
</div>
<div className="flex flex-row gap-6 items-center">
<Image
className="variant-logo"
alt="Variant logo"
src="./images/variant-logo-1.svg"
width="65"
height="16"
/>
<NavBarUserIcon />
</div>
</div>
);
}
36 changes: 36 additions & 0 deletions frontend/src/components/NavBarDropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"use client";
import React, { useState } from "react";
import { signOut } from "next-auth/react";

export default function Dropdown(props: { initials: string }) {
const [isOpen, setIsOpen] = useState<boolean>(false);

function toggle() {
setIsOpen((old) => !old);
}

const transClass = isOpen ? "flex" : "hidden";

return (
<>
<div className="relative">
<button
className="flex rounded-full border border-white h-9 w-9 overflow-hidden justify-center items-center"
onClick={toggle}
>
<p className="text-white body-small">{props.initials}</p>
</button>
<div
className={`absolute origin-right right-0 bg-primary_l4 w-24 flex flex-col p-4 rounded-sm ${transClass}`}
>
<button
className="hover:opacity-70 text-center "
onClick={() => signOut()}
>
Logg ut
</button>
</div>
</div>
</>
);
}
26 changes: 26 additions & 0 deletions frontend/src/components/NavBarLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use client";
import { usePathname } from "next/navigation";

export default function NavBarLink(props: { text: string; path: string }) {
const pathname = usePathname();
const isCurrentPath = props.path.includes(pathname);

if (isCurrentPath) {
return (
<a
className="p-4 body-large-bold text-white flex justify-items-center border-b-[3px] border-secondary_default "
href={`${props.path}`}
>
{props.text}
</a>
);
} else
return (
<a
className="p-4 body-large text-white opacity-70 flex justify-items-center hover:opacity-100 "
href={`${props.path}`}
>
{props.text}
</a>
);
}
18 changes: 18 additions & 0 deletions frontend/src/components/NavBarUserIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
authOptions,
getCustomServerSession,
} from "@/app/api/auth/[...nextauth]/route";
import Dropdown from "./NavBarDropdown";

export default async function NavBarUserIcon() {
const session = await getCustomServerSession(authOptions);
const initials =
session.user?.name
?.split(" ")
.map((n) => n.charAt(0).toUpperCase())
.join("") || "";

if (session) {
return <Dropdown initials={initials} />;
}
}
15 changes: 0 additions & 15 deletions frontend/src/components/PageLayout.tsx

This file was deleted.

18 changes: 0 additions & 18 deletions frontend/src/components/ThemeRegistry/ThemeRegistry.tsx

This file was deleted.

22 changes: 0 additions & 22 deletions frontend/src/components/ThemeRegistry/theme.ts

This file was deleted.

44 changes: 0 additions & 44 deletions frontend/src/components/VibesNavBar.tsx

This file was deleted.

25 changes: 0 additions & 25 deletions frontend/src/components/VibesNavBarTabs.tsx

This file was deleted.

22 changes: 0 additions & 22 deletions frontend/src/components/vibes-buttons/SignInButton.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions frontend/src/components/vibes-buttons/SignInSignOutButton.tsx

This file was deleted.

64 changes: 0 additions & 64 deletions frontend/src/components/vibes-buttons/SignOutButton.tsx

This file was deleted.

0 comments on commit 095dc4d

Please sign in to comment.