moonstream/frontend/src/components/LandingNavbar.js

190 wiersze
6.4 KiB
JavaScript
Czysty Zwykły widok Historia

2021-07-19 11:50:35 +00:00
import React, { Fragment, useContext } from "react";
2021-07-13 11:35:46 +00:00
import RouterLink from "next/link";
import {
Button,
Image,
ButtonGroup,
Link,
2021-08-26 13:18:31 +00:00
Flex,
Menu,
MenuButton,
MenuList,
MenuItem,
Portal,
2022-11-14 18:09:31 +00:00
Box,
Text,
2021-07-13 11:35:46 +00:00
} from "@chakra-ui/react";
2022-11-14 10:59:56 +00:00
import { ChevronDownIcon } from "@chakra-ui/icons";
2021-07-13 11:35:46 +00:00
import useModals from "../core/hooks/useModals";
import UIContext from "../core/providers/UIProvider/context";
2021-07-19 11:50:35 +00:00
import ChakraAccountIconButton from "./AccountIconButton";
2021-08-18 12:39:53 +00:00
import RouteButton from "./RouteButton";
2022-11-14 10:59:56 +00:00
import { PAGETYPE, SITEMAP, PRIMARY_MOON_LOGO_URL } from "../core/constants";
2021-08-20 13:07:25 +00:00
import router from "next/router";
2021-10-27 13:01:26 +00:00
import { MODAL_TYPES } from "../core/providers/OverlayProvider/constants";
2022-11-14 10:59:56 +00:00
import LandingBarMobile from "./LandingBarMobile";
2021-07-13 11:35:46 +00:00
const LandingNavbar = () => {
const ui = useContext(UIContext);
const { toggleModal } = useModals();
return (
<>
2022-11-14 10:59:56 +00:00
{ui.isMobileView && <LandingBarMobile />}
2021-08-26 13:18:31 +00:00
{!ui.isMobileView && (
<>
2022-11-14 10:59:56 +00:00
<Flex
pl={ui.isMobileView ? 2 : "60px"}
justifySelf="flex-start"
2022-11-19 09:27:46 +00:00
h={ui.isMobileView && !ui.isAppView ? "89px" : "72px"}
2022-11-14 10:59:56 +00:00
py={1}
flexBasis="200px"
flexGrow={0.6}
id="Logo Container"
alignItems="center"
>
<RouterLink href="/" passHref>
<Link
as={Image}
w={"160px"}
justifyContent="left"
src={PRIMARY_MOON_LOGO_URL}
alt="Moonstream logo"
/>
</RouterLink>
</Flex>
2022-10-13 17:33:27 +00:00
<ButtonGroup variant="link" spacing={4} pr={16} flexGrow={0.5}>
{SITEMAP.map((item, idx) => {
return (
<React.Fragment key={`Fragment-${idx}`}>
2022-05-23 11:49:45 +00:00
{!item.children && item.type !== PAGETYPE.FOOTER_CATEGORY && (
<RouteButton
key={`${idx}-${item.title}-landing-all-links`}
variant="link"
href={item.path}
2022-11-01 15:04:24 +00:00
color="black"
2022-11-14 18:09:31 +00:00
fontSize="16px"
isActive={!!(router.pathname === item.path)}
>
{item.title}
</RouteButton>
)}
2022-05-23 11:49:45 +00:00
{item.type !== PAGETYPE.FOOTER_CATEGORY && item.children && (
2022-11-13 17:01:31 +00:00
<Menu autoSelect="false">
<MenuButton
as={Button}
rightIcon={<ChevronDownIcon />}
color="white"
2022-11-21 07:15:26 +00:00
fontWeight="500"
2022-11-14 18:09:31 +00:00
fontSize="16px"
2022-11-21 07:15:26 +00:00
_expanded={{ color: "white", fontWeight: "700" }}
_focus={{ textDecoration: "none" }}
_hover={{ textDecoration: "none", fontWeight: "700" }}
2022-11-13 17:01:31 +00:00
>
{item.title}
</MenuButton>
<Portal>
2022-11-13 17:01:31 +00:00
<MenuList
zIndex={100}
2022-11-21 07:15:26 +00:00
bg="black.300"
2022-11-13 17:01:31 +00:00
w="auto"
minW="auto"
borderRadius="10px"
p="20px 20px 10px 20px"
border="1px solid white"
>
{item.children.map((child, idx) => (
<RouterLink
shallow={true}
key={`${idx}-${item.title}-menu-links`}
href={child.path}
passHref
>
2022-11-13 17:01:31 +00:00
<MenuItem
key={`menu-${idx}`}
as={"a"}
m={0}
color="white"
fontWeight="400"
2022-11-14 18:09:31 +00:00
fontSize="16px"
2022-11-13 17:01:31 +00:00
px="0px"
mb="10px"
h="22px"
_hover={{
2022-11-21 07:15:26 +00:00
backgroundColor: "black.300",
color: "orange.1000",
2022-11-13 17:01:31 +00:00
fontWeight: "700",
}}
2022-11-21 07:15:26 +00:00
_focus={{ backgroundColor: "black.300" }}
2022-11-13 17:01:31 +00:00
>
{child.title}
</MenuItem>
</RouterLink>
))}
</MenuList>
</Portal>
</Menu>
)}
</React.Fragment>
);
})}
2022-10-13 17:33:27 +00:00
</ButtonGroup>
<ButtonGroup variant="link" spacing={4} pr={16}>
2021-08-26 13:18:31 +00:00
{ui.isLoggedIn && (
<RouterLink href="/welcome" passHref>
2022-11-14 18:09:31 +00:00
<Box
2022-11-21 07:15:26 +00:00
bg="orange.1000"
alignSelf={"center"}
2022-11-14 18:09:31 +00:00
fontWeight="700"
borderRadius="15px"
w="51px"
h="32px"
textAlign="center"
px="10px"
cursor="pointer"
_hover={{
backgroundColor: "#F4532F",
}}
2021-07-13 11:35:46 +00:00
>
2022-11-14 18:09:31 +00:00
<Text fontSize="16px" lineHeight="32px">
App
</Text>
</Box>
2021-08-26 13:18:31 +00:00
</RouterLink>
)}
2021-11-08 16:23:09 +00:00
{!ui.isLoggedIn && (
2021-08-26 13:18:31 +00:00
<Button
2022-11-21 07:15:26 +00:00
bg="orange.1000"
2021-11-08 16:23:09 +00:00
variant="solid"
2021-11-15 16:01:20 +00:00
onClick={() => toggleModal({ type: MODAL_TYPES.SIGNUP })}
2021-08-26 13:18:31 +00:00
size="sm"
2022-11-14 18:09:31 +00:00
fontWeight="700"
2021-08-26 13:18:31 +00:00
borderRadius="2xl"
2022-10-13 03:11:21 +00:00
textColor="white"
2022-11-14 18:09:31 +00:00
_hover={{
backgroundColor: "#F4532F",
}}
2021-08-26 13:18:31 +00:00
>
2022-10-13 14:25:23 +00:00
Sign up
2021-08-26 13:18:31 +00:00
</Button>
2021-11-08 16:23:09 +00:00
)}
2021-08-26 13:18:31 +00:00
{!ui.isLoggedIn && (
<Button
color="white"
2021-11-09 12:28:41 +00:00
onClick={() => toggleModal({ type: MODAL_TYPES.LOGIN })}
2021-08-26 13:18:31 +00:00
fontWeight="400"
>
Log in
</Button>
)}
{ui.isLoggedIn && (
<ChakraAccountIconButton variant="link" colorScheme="orange" />
2021-08-26 13:18:31 +00:00
)}
</ButtonGroup>
</>
)}
2021-07-13 11:35:46 +00:00
</>
);
};
export default LandingNavbar;