import React from "react";
import {
Box,
Button,
HStack,
IconButton,
Menu,
MenuButton,
MenuList,
MenuItem,
useDisclosure,
} from "@chakra-ui/react";
import { HamburgerIcon } from "@chakra-ui/icons";
import { Link, useLocation } from "react-router-dom";
import { ChevronLeftIcon } from "@chakra-ui/icons";
import Image from "next/image";
import useCurrentUser, {
useAuthModeFeatureFlag,
useLoginActions,
} from "./components/useCurrentUser";
import HomeLinkIcon from "./images/home-link-icon.png";
function GlobalHeader() {
return (
);
}
function HomeLink(props) {
const { pathname } = useLocation();
const isHomePage = pathname === "/";
return (
Dress to Impress
);
}
function UserNavBarSection() {
const { isLoading, isLoggedIn, id, username } = useCurrentUser();
const { logout } = useLoginActions();
if (isLoading) {
return null;
}
if (isLoggedIn) {
return (
{username && (
Hi, {username}!
)}
{id && (
Lists
)}
Outfits
Modeling
logout({ returnTo: window.location.origin })}
>
Log out
);
} else {
return (
Modeling
);
}
}
function LoginButton() {
const authMode = useAuthModeFeatureFlag();
const { startLogin } = useLoginActions();
const { isOpen, onOpen, onClose } = useDisclosure();
const onClick = () => {
if (authMode === "auth0") {
startLogin();
} else if (authMode === "db") {
onOpen();
} else {
throw new Error(`unexpected auth mode: ${JSON.stringify(authMode)}`);
}
};
return (
<>
Log in
{authMode === "db" && (
)}
>
);
}
// I don't wanna load all these Chakra components as part of the bundle for
// every single page. Split it out!
const LoginModal = React.lazy(() => import("./components/LoginModal"));
/**
* Renders the given children as a dropdown menu or as a list
* of buttons, depending on the screen size.
*
* It actually renders both, and shows/hides them by media query!
*/
function NavLinksList({ children }) {
return (
<>
{React.Children.map(children, (c) => (
))}
>
);
}
function NavLinkItem() {
throw new Error(
`NavLinkItem should only be rendered in a NavLinksList, which should ` +
`render it as both a MenuItem or NavButton element. That way, we can ` +
`show the best layout depending on a CSS media query!`
);
}
const NavButton = React.forwardRef(({ icon, ...props }, ref) => {
const Component = icon ? IconButton : Button;
// Opacity is in a separate Box, to avoid overriding the built-in Button
// hover/focus states.
return (
);
});
export default GlobalHeader;