Skip to content

Commit

Permalink
Fix navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Spazzinq committed Nov 13, 2024
1 parent 4906d42 commit 18528ff
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 131 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
# Force push code to GitLab for deployment

name: Mirror

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Node.js CI

on:
push:
branches: [ "main", "dcrepublic-dev", "v6ctor-dev"]
branches: ["main", "dcrepublic-dev", "v6ctor-dev"]

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ go mod tidy
```

```bash
go run main.go -semester=[spring|fall] -year=[202x] #defautl is fall 2024
go run main.go -semester=spring -year=2025 # Change to semester of choice

```

Expand Down
225 changes: 99 additions & 126 deletions components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,66 +18,33 @@ import {
DropdownItem,
} from "@nextui-org/dropdown";
import { Link } from "@nextui-org/link";
import { Spacer } from "@nextui-org/spacer";
import NextLink from "next/link";
import { usePathname } from "next/navigation";
import { button as buttonStyles } from "@nextui-org/theme";
import InputIcon from "@mui/icons-material/Input";
import AccountCircleIcon from "@mui/icons-material/AccountCircle";
import axios from "axios";

import { siteConfig } from "../config/site";
import { ThemeSwitch } from "../components/theme-switch";
import { title } from "../components/primitives";
import { Button } from "@nextui-org/button";

export const Navbar = (props: any) => {
const pathname = usePathname();
const { data: session, status } = useSession();

let authenticated;
let loginLink: any;
let adminDashLink: any;
let nameButton;

if (props.hasOwnProperty("login")) {
loginLink = null;
nameButton = null;
} else {
if (status === "authenticated") {
authenticated = true;
axios
.post("/api/user", {
session: session,
})
.then(function (response) {
//console.log(response);
})
.catch(function (error) {
console.log(error);
});

loginLink = (
<div role="button" onClick={() => signOut()}>
Log out
</div>
);

if (session.user?.role === "admin") {
adminDashLink = (
<DropdownItem key="admin" href="/admin">
<div>Admin</div>
</DropdownItem>
);
}
nameButton = session.user?.name;
} else {
authenticated = false;
loginLink = <></>;
nameButton = (
<div>
Log In <InputIcon />
</div>
);
}
if (status === "authenticated") {
axios
.post("/api/user", {
session: session,
})
.then((response) => {
//console.log(response);
})
.catch((error) => {
console.log(error);
});
}

return (
Expand All @@ -103,23 +70,23 @@ export const Navbar = (props: any) => {
</NavbarBrand>
</NavbarContent>

<NavbarContent justify="start" className="hidden md:flex">
<Spacer x={24} />
<ul className="gap-4 flex-row justify-start ml-2">
{siteConfig.navItems.map((item) => (
<Link
key={item.href}
className={buttonStyles({
color: "primary",
radius: "full",
variant: pathname == item.href ? "shadow" : "ghost",
})}
href={item.href}
>
{item.label}
</Link>
))}
</ul>
<NavbarContent
justify="center"
className="hidden md:flex gap-3 flex-row"
>
{siteConfig.navItems.map((item) => (
<Link
key={item.href}
className={buttonStyles({
color: "primary",
radius: "full",
variant: pathname === item.href ? "shadow" : "ghost",
})}
href={item.href}
>
{item.label}
</Link>
))}
</NavbarContent>

<NavbarContent
Expand All @@ -131,33 +98,32 @@ export const Navbar = (props: any) => {
</NavbarItem>

<NavbarItem>
<Dropdown>
<DropdownTrigger>
<Link
className={buttonStyles({
color: "primary",
radius: "full",
variant: "ghost",
})}
onClick={
authenticated
? () => {}
: () => signIn("keycloak", { callbackUrl: "/" })
}
>
{nameButton}
</Link>
</DropdownTrigger>

{authenticated ? (
{status === "authenticated" ? (
<Dropdown>
<DropdownTrigger>
<Button variant="bordered">
<AccountCircleIcon />
{session.user?.name || "Account"}
</Button>
</DropdownTrigger>
<DropdownMenu aria-label="Static Actions">
{adminDashLink}
<DropdownItem key="loginLink">{loginLink}</DropdownItem>
{/* Causes an awful error if rendered conditionally */}
{/* <DropdownItem key="admin" href="/admin">
Admin
</DropdownItem> */}
<DropdownItem key="signOut" onClick={() => signOut()}>
Sign Out
</DropdownItem>
</DropdownMenu>
) : (
<></>
)}
</Dropdown>
</Dropdown>
) : (
<Button
variant="bordered"
onClick={() => signIn("keycloak", { callbackUrl: "/" })}
>
<InputIcon /> Log In
</Button>
)}
</NavbarItem>
</NavbarContent>

Expand All @@ -167,46 +133,53 @@ export const Navbar = (props: any) => {
</NavbarContent>

{/* Mobile?*/}
<NavbarMenu>
<div className="mx-4 mt-2 flex flex-col gap-2">
{siteConfig.navItems.map((item, index) => (
<NavbarMenuItem key={`${item}-${index}`}>
<Link href={item.href} size="lg">
{item.label}
</Link>
</NavbarMenuItem>
))}
{/* <NavbarMenu>
<div className="mx-4 mt-2 flex flex-col gap-2">
{siteConfig.navItems.map((item, index) => (
<NavbarMenuItem key={`${item}-${index}`}>
<Link href={item.href} size="lg">
{item.label}
</Link>
</NavbarMenuItem>
))}
<NavbarItem>
<Dropdown>
<DropdownTrigger>
<Link
className={buttonStyles({
color: "primary",
radius: "full",
variant: "ghost",
})}
onClick={
authenticated
? () => {}
: () => signIn("keycloak", { callbackUrl: "/" })
}
>
{nameButton}
</Link>
</DropdownTrigger>
<NavbarItem>
<Dropdown>
<DropdownTrigger>
<Link
className={buttonStyles({
color: "primary",
radius: "full",
variant: "ghost",
})}
onClick={
authenticated
? () => {}
: () => signIn("keycloak", { callbackUrl: "/" })
}
>
{nameButton}
</Link>
</DropdownTrigger>
{authenticated ? (
<DropdownMenu aria-label="Static Actions">
<DropdownItem key="loginLink">{loginLink}</DropdownItem>
</DropdownMenu>
) : (
<></>
)}
</Dropdown>
</NavbarItem>
</div>
</NavbarMenu>
{authenticated ? (
<DropdownMenu
aria-label="Static Actions"
onAction={(key) => {
authenticated
? signOut()
: signIn("keycloak", { callbackUrl: "/" });
}}
>
<DropdownItem key="loginLink">Sign Out</DropdownItem>
</DropdownMenu>
) : (
<></>
)}
</Dropdown>
</NavbarItem>
</div>
</NavbarMenu> */}
</NextUINavbar>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:
- 9229:9229
networks:
- internal
command: sh -c "npm install --silent && npx prisma generate && npm run dev "
command: sh -c "npm install --silent && npx prisma migrate dev --name init && npx prisma generate && npm run dev "

postgres:
image: postgres:16.4-bullseye
Expand Down

0 comments on commit 18528ff

Please sign in to comment.