"use client"; import { Image, Link, NavbarBrand, Navbar as NavbarBase, NavbarContent, Divider, } from "@nextui-org/react"; import NavbarLink from "./NavbarLink"; import NavbarSearchbar from "./NavbarSearchbar"; import NavbarButtonLink from "./NavbarButtonLink"; import { Bell, CalendarPlus, Gamepad2, LogInIcon, NotebookPen, Shield, SquarePen, } from "lucide-react"; import NextImage from "next/image"; import { useEffect, useState } from "react"; import { usePathname } from "next/navigation"; import { getCookie, hasCookie } from "@/helpers/cookie"; import { getCurrentJam, joinJam } from "@/helpers/jam"; import { JamType } from "@/types/JamType"; import { UserType } from "@/types/UserType"; import NavbarUser from "./PCNavbarUser"; import NavbarButtonAction from "./NavbarButtonAction"; import { toast } from "react-toastify"; import NavbarIconLink from "./NavbarIconLink"; import ThemeToggle from "../theme-toggle"; export default function PCNavbar() { const pathname = usePathname(); const [jam, setJam] = useState(); const [isInJam, setIsInJam] = useState(); const [user, setUser] = useState(); useEffect(() => { loadUser(); async function loadUser() { const currentJam = await getCurrentJam(); setJam(currentJam); if (!hasCookie("token")) { setUser(undefined); return; } const response = await fetch( process.env.NEXT_PUBLIC_MODE === "PROD" ? `https://d2jam.com/api/v1/self?username=${getCookie("user")}` : `http://localhost:3005/api/v1/self?username=${getCookie("user")}`, { headers: { authorization: `Bearer ${getCookie("token")}` }, credentials: "include", } ); const user = await response.json(); if ( currentJam && user.jams.filter((jam: JamType) => jam.id == currentJam.id).length > 0 ) { setIsInJam(true); } else { setIsInJam(false); } if (response.status == 200) { setUser(user); } else { setUser(undefined); } } }, [pathname]); return ( {/* Left side navbar items */} Dare2Jam logo {/* Right side navbar items */} {user && } {user && jam && isInJam && ( } name="Create Game" href="/create-game" /> )} {user && jam && !isInJam && ( } name="Join jam" onPress={async () => { const currentJam = await getCurrentJam(); if (!currentJam) { toast.error("There is no jam to join"); return; } if (await joinJam(currentJam.id)) { setIsInJam(true); } }} /> )} {user && ( } name="Create Post" href="/create-post" /> )} {user && } href="/inbox" />} {user && user.mod && ( } href="/reports" /> )} {!user && ( } name="Log In" href="/login" /> )} {!user && ( } name="Sign Up" href="/signup" /> )} {user && } ); }