add site title to left nav, move Modeling to right

Honestly I don't think this is the long-term home for the Modeling link, I think it'll become a homepage-only link as we add more modules there. But I wanted to get it out of the way!
This commit is contained in:
Emi Matchu 2020-09-20 19:36:51 -07:00
parent abda9e4687
commit 34112b30df

View file

@ -1,18 +1,8 @@
import React from "react"; import React from "react";
import { import { Box, Button, HStack, IconButton } from "@chakra-ui/core";
Box,
Button,
HStack,
IconButton,
Menu,
MenuButton,
MenuItem,
MenuList,
useBreakpointValue,
} from "@chakra-ui/core";
import { Link, useLocation } from "react-router-dom"; import { Link, useLocation } from "react-router-dom";
import { useAuth0 } from "@auth0/auth0-react"; import { useAuth0 } from "@auth0/auth0-react";
import { ChevronLeftIcon, HamburgerIcon } from "@chakra-ui/icons"; import { ChevronLeftIcon } from "@chakra-ui/icons";
import useCurrentUser from "./components/useCurrentUser"; import useCurrentUser from "./components/useCurrentUser";
@ -20,15 +10,20 @@ import HomeLinkIcon from "../images/home-link-icon.png";
import HomeLinkIcon2x from "../images/home-link-icon@2x.png"; import HomeLinkIcon2x from "../images/home-link-icon@2x.png";
function GlobalNavBar() { function GlobalNavBar() {
const navStyle = useBreakpointValue({ base: "menu", md: "buttons" }); const { pathname } = useLocation();
const isHomePage = pathname === "/";
return ( return (
<Box display="flex" alignItems="center" flexWrap="wrap"> <Box display="flex" alignItems="center" flexWrap="wrap">
<HStack alignItems="center" spacing="2" marginRight="4"> <HomeLink showArrow={!isHomePage} />
<HomeLink /> <Box
{navStyle === "menu" && <NavMenu />} display="flex"
{navStyle === "buttons" && <NavButtons />} alignItems="center"
</HStack> opacity={isHomePage ? "0" : "1"}
transition="0.2s opacity"
>
<DressToImpressTitle marginLeft="2" />
</Box>
<Box marginLeft="auto"> <Box marginLeft="auto">
<UserNavBarSection /> <UserNavBarSection />
</Box> </Box>
@ -36,10 +31,7 @@ function GlobalNavBar() {
); );
} }
function HomeLink() { function HomeLink({ showArrow }) {
const { pathname } = useLocation();
const isHomePage = pathname === "/";
return ( return (
<Box <Box
as={Link} as={Link}
@ -56,8 +48,8 @@ function HomeLink() {
<Box <Box
position="absolute" position="absolute"
right="100%" right="100%"
opacity={isHomePage ? "0" : "1"} opacity={showArrow ? "1" : "0"}
transform={isHomePage ? "translateX(3px)" : "none"} transform={showArrow ? "none" : "translateX(3px)"}
transition="all 0.2s" transition="all 0.2s"
> >
<ChevronLeftIcon /> <ChevronLeftIcon />
@ -104,46 +96,41 @@ function UserNavBarSection() {
</Box> </Box>
)} )}
{id && ( {id && (
<NavButton <NavButton as={Link} to={`/user/${id}/items`}>
as={Link}
to={`/user/${id}/items`}
size="sm"
variant="outline"
>
Items Items
</NavButton> </NavButton>
)} )}
<NavButton as={Link} to="/modeling">
Modeling
</NavButton>
<NavButton onClick={() => logout({ returnTo: window.location.origin })}> <NavButton onClick={() => logout({ returnTo: window.location.origin })}>
Log out Log out
</NavButton> </NavButton>
</HStack> </HStack>
); );
} else { } else {
return <NavButton onClick={() => loginWithRedirect()}>Log in</NavButton>;
}
}
function NavMenu() {
return (
<Menu>
<MenuButton as={NavButton} icon={<HamburgerIcon />} />
<MenuList fontSize="sm">
<MenuItem as={Link} to="/">
Home
</MenuItem>
<MenuItem as={Link} to="/modeling">
Modeling
</MenuItem>
</MenuList>
</Menu>
);
}
function NavButtons() {
return ( return (
<HStack align="center" spacing="2">
<NavButton as={Link} to="/modeling"> <NavButton as={Link} to="/modeling">
Modeling Modeling
</NavButton> </NavButton>
<NavButton onClick={() => loginWithRedirect()}>Log in</NavButton>
</HStack>
);
}
}
function DressToImpressTitle(props) {
return (
<Box
fontFamily="Delicious"
fontWeight="bold"
fontSize="2xl"
display={{ base: "none", sm: "block" }}
{...props}
>
Dress to Impress
</Box>
); );
} }