import { Box, Burger, Container, createStyles, Group, Header as MantineHeader, Paper, Stack, Text, Transition, } from "@mantine/core"; import { useDisclosure } from "@mantine/hooks"; import Link from "next/link"; import { useRouter } from "next/router"; import { ReactNode, useEffect, useState } from "react"; import useConfig from "../../hooks/config.hook"; import useUser from "../../hooks/user.hook"; import useTranslate from "../../hooks/useTranslate.hook"; import Logo from "../Logo"; import ActionAvatar from "./ActionAvatar"; import NavbarShareMenu from "./NavbarShareMenu"; const HEADER_HEIGHT = 60; const webroot = process.env.WEBROOT || ""; type NavLink = { link?: string; label?: string; component?: ReactNode; action?: () => Promise; }; const useStyles = createStyles((theme) => ({ root: { position: "relative", zIndex: 1, }, dropdown: { position: "absolute", top: HEADER_HEIGHT, left: 0, right: 0, zIndex: 0, borderTopRightRadius: 0, borderTopLeftRadius: 0, borderTopWidth: 0, overflow: "hidden", [theme.fn.largerThan("sm")]: { display: "none", }, }, header: { display: "flex", justifyContent: "space-between", alignItems: "center", height: "100%", }, links: { [theme.fn.smallerThan("sm")]: { display: "none", }, }, burger: { [theme.fn.largerThan("sm")]: { display: "none", }, }, link: { display: "block", lineHeight: 1, padding: "8px 12px", borderRadius: theme.radius.sm, textDecoration: "none", color: theme.colorScheme === "dark" ? theme.colors.dark[0] : theme.colors.gray[7], fontSize: theme.fontSizes.sm, fontWeight: 500, "&:hover": { backgroundColor: theme.colorScheme === "dark" ? theme.colors.dark[6] : theme.colors.gray[0], }, [theme.fn.smallerThan("sm")]: { borderRadius: 0, padding: theme.spacing.md, }, }, linkActive: { "&, &:hover": { backgroundColor: theme.colorScheme === "dark" ? theme.fn.rgba(theme.colors[theme.primaryColor][9], 0.25) : theme.colors[theme.primaryColor][0], color: theme.colors[theme.primaryColor][theme.colorScheme === "dark" ? 3 : 7], }, }, })); const Header = () => { const { user } = useUser(); const router = useRouter(); const config = useConfig(); const t = useTranslate(); const [opened, toggleOpened] = useDisclosure(false); const [currentRoute, setCurrentRoute] = useState(""); useEffect(() => { setCurrentRoute(router.pathname); }, [router.pathname]); const authenticatedLinks: NavLink[] = [ { link: webroot + "/upload", label: t("navbar.upload"), }, { component: , }, { component: , }, ]; let unauthenticatedLinks: NavLink[] = [ { link: webroot + "/auth/signIn", label: t("navbar.signin"), }, ]; if (config.get("share.allowUnauthenticatedShares")) { unauthenticatedLinks.unshift({ link: webroot + "/upload", label: t("navbar.upload"), }); } if (config.get("general.showHomePage")) unauthenticatedLinks.unshift({ link: webroot + "/", label: t("navbar.home"), }); if (config.get("share.allowRegistration")) unauthenticatedLinks.push({ link: webroot + "/auth/signUp", label: t("navbar.signup"), }); const { classes, cx } = useStyles(); const items = ( <> {(user ? authenticatedLinks : unauthenticatedLinks).map((link, i) => { if (link.component) { return ( {link.component} ); } return ( toggleOpened.toggle()} className={cx(classes.link, { [classes.linkActive]: currentRoute == link.link, })} > {link.label} ); })} ); return ( {config.get("general.appName")} {items} toggleOpened.toggle()} className={classes.burger} size="sm" /> {(styles) => ( {items} )} ); }; export default Header;