"use client"; import { Navbar as NavbarBase, NavbarBrand, NavbarContent, NavbarItem, } from "@nextui-org/navbar"; import { Link } from "@nextui-org/link"; import { Divider } from "@nextui-org/divider"; import { Avatar, Button, Dropdown, DropdownItem, DropdownMenu, DropdownTrigger, Image, Tooltip, } from "@nextui-org/react"; import { SiDiscord, SiForgejo, SiGithub } from "@icons-pack/react-simple-icons"; import { CalendarPlus, Gamepad2, LogInIcon, Menu, NotebookPen, SquarePen, } from "lucide-react"; import { useEffect, useState } from "react"; import { hasCookie, getCookie } from "@/helpers/cookie"; import { usePathname } from "next/navigation"; import { UserType } from "@/types/UserType"; import { getCurrentJam, joinJam } from "@/helpers/jam"; import { toast } from "react-toastify"; import { JamType } from "@/types/JamType"; export default function Navbar() { const [user, setUser] = useState(); const pathname = usePathname(); const [isMobile, setIsMobile] = useState(false); const [jam, setJam] = useState(); const [isInJam, setIsInJam] = 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")}` }, } ); 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]); useEffect(() => { const handleResize = () => { setIsMobile(window.innerWidth <= 768); // Adjust breakpoint as needed }; handleResize(); window.addEventListener("resize", handleResize); return () => window.removeEventListener("resize", handleResize); }, []); return ( Dare2Jam logo {isMobile ? ( user ? ( {jam && isInJam ? ( Create Game ) : null} {jam && !isInJam ? ( { try { const currentJam = await getCurrentJam(); if (!currentJam) { toast.error("There is no jam to join"); return; } if (await joinJam(currentJam.id)) { setIsInJam(true); } } catch (error) { console.error("Error during join process:", error); } }} > Join Event ) : null} Create Post Profile Settings GitHub Forgejo Discord Logout ) : ( GitHub Forgejo Discord Log In Sign Up ) ) : (
{user && jam && isInJam && ( )} {user && jam && !isInJam && ( )} {user && ( )}
GitHub
Source Code
} >
Forgejo
Source Code
} >
{!user ? (
) : ( Profile Settings Logout )} )} ); } /* {isMobile ? ( // Mobile view user ? ( Create Post Logout ) : ( GitHub Forgejo Discord Log In Sign Up ) ) : ( user && ( )
GitHub
Source Code
} >
Forgejo
Source Code
} >
{!user ? (
) : ( Logout )} ) */