Commit 21282a71 authored by tom's avatar tom

hide account nav for unauth users

parent 6830dc22
...@@ -39,7 +39,7 @@ const Burger = () => { ...@@ -39,7 +39,7 @@ const Burger = () => {
> >
<DrawerOverlay/> <DrawerOverlay/>
<DrawerContent maxWidth="260px"> <DrawerContent maxWidth="260px">
<DrawerBody p={ 6 }> <DrawerBody p={ 6 } display="flex" flexDirection="column">
<Flex alignItems="center" justifyContent="space-between"> <Flex alignItems="center" justifyContent="space-between">
<NetworkLogo onClick={ handleNetworkLogoClick }/> <NetworkLogo onClick={ handleNetworkLogoClick }/>
<NetworkMenuButton <NetworkMenuButton
......
...@@ -20,9 +20,10 @@ const VERSION_URL = `https://github.com/blockscout/blockscout/tree/${ BLOCKSCOUT ...@@ -20,9 +20,10 @@ const VERSION_URL = `https://github.com/blockscout/blockscout/tree/${ BLOCKSCOUT
interface Props { interface Props {
isCollapsed?: boolean; isCollapsed?: boolean;
isAuth?: boolean;
} }
const NavFooter = ({ isCollapsed }: Props) => { const NavFooter = ({ isCollapsed, isAuth }: Props) => {
const isMobile = useIsMobile(); const isMobile = useIsMobile();
const width = (() => { const width = (() => {
...@@ -33,6 +34,14 @@ const NavFooter = ({ isCollapsed }: Props) => { ...@@ -33,6 +34,14 @@ const NavFooter = ({ isCollapsed }: Props) => {
return isCollapsed ? '20px' : '180px'; return isCollapsed ? '20px' : '180px';
})(); })();
const marginTop = (() => {
if (!isAuth) {
return 'auto';
}
return isMobile ? 6 : 20;
})();
return ( return (
<VStack <VStack
as="footer" as="footer"
...@@ -41,7 +50,7 @@ const NavFooter = ({ isCollapsed }: Props) => { ...@@ -41,7 +50,7 @@ const NavFooter = ({ isCollapsed }: Props) => {
borderColor={ useColorModeValue('blackAlpha.200', 'whiteAlpha.200') } borderColor={ useColorModeValue('blackAlpha.200', 'whiteAlpha.200') }
width={ width } width={ width }
paddingTop={ isMobile ? 6 : 8 } paddingTop={ isMobile ? 6 : 8 }
marginTop={ isMobile ? 6 : 20 } marginTop={ marginTop }
alignItems="flex-start" alignItems="flex-start"
alignSelf="center" alignSelf="center"
color="gray.500" color="gray.500"
......
...@@ -17,15 +17,16 @@ const NavigationDesktop = () => { ...@@ -17,15 +17,16 @@ const NavigationDesktop = () => {
const { mainNavItems, accountNavItems } = useNavItems(); const { mainNavItems, accountNavItems } = useNavItems();
const isLargeScreen = useBreakpointValue({ base: false, xl: true }); const isLargeScreen = useBreakpointValue({ base: false, xl: true });
const cookieValue = cookies.get(cookies.NAMES.NAV_BAR_COLLAPSED); const navBarCollapsedCookie = cookies.get(cookies.NAMES.NAV_BAR_COLLAPSED);
const isAuth = Boolean(cookies.get(cookies.NAMES.API_TOKEN));
const [ isCollapsed, setCollapsedState ] = React.useState(cookieValue === 'true'); const [ isCollapsed, setCollapsedState ] = React.useState(navBarCollapsedCookie === 'true');
React.useEffect(() => { React.useEffect(() => {
if (!cookieValue) { if (!navBarCollapsedCookie) {
setCollapsedState(!isLargeScreen); setCollapsedState(!isLargeScreen);
} }
}, [ isLargeScreen, cookieValue ]); }, [ isLargeScreen, navBarCollapsedCookie ]);
const handleTogglerClick = React.useCallback(() => { const handleTogglerClick = React.useCallback(() => {
setCollapsedState((flag) => !flag); setCollapsedState((flag) => !flag);
...@@ -70,13 +71,15 @@ const NavigationDesktop = () => { ...@@ -70,13 +71,15 @@ const NavigationDesktop = () => {
<NavLink key={ item.text } { ...item } isCollapsed={ isCollapsed } isActive={ router.asPath.startsWith(item.pathname) }/>) } <NavLink key={ item.text } { ...item } isCollapsed={ isCollapsed } isActive={ router.asPath.startsWith(item.pathname) }/>) }
</VStack> </VStack>
</Box> </Box>
<Box as="nav" mt={ 12 }> { isAuth && (
<VStack as="ul" spacing="2" alignItems="flex-start" overflow="hidden"> <Box as="nav" mt={ 12 }>
{ accountNavItems.map((item) => <VStack as="ul" spacing="2" alignItems="flex-start" overflow="hidden">
<NavLink key={ item.text } { ...item } isCollapsed={ isCollapsed } isActive={ router.asPath.startsWith(item.pathname) }/>) } { accountNavItems.map((item) =>
</VStack> <NavLink key={ item.text } { ...item } isCollapsed={ isCollapsed } isActive={ router.asPath.startsWith(item.pathname) }/>) }
</Box> </VStack>
<NavFooter isCollapsed={ isCollapsed }/> </Box>
) }
<NavFooter isCollapsed={ isCollapsed } isAuth={ isAuth }/>
<ChevronLeftIcon <ChevronLeftIcon
width={ 6 } width={ 6 }
height={ 6 } height={ 6 }
......
...@@ -2,6 +2,7 @@ import { Box, VStack } from '@chakra-ui/react'; ...@@ -2,6 +2,7 @@ import { Box, VStack } from '@chakra-ui/react';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import React from 'react'; import React from 'react';
import * as cookies from 'lib/cookies';
import useNavItems from 'lib/hooks/useNavItems'; import useNavItems from 'lib/hooks/useNavItems';
import NavFooter from 'ui/blocks/navigation/NavFooter'; import NavFooter from 'ui/blocks/navigation/NavFooter';
import NavLink from 'ui/blocks/navigation/NavLink'; import NavLink from 'ui/blocks/navigation/NavLink';
...@@ -9,6 +10,7 @@ import NavLink from 'ui/blocks/navigation/NavLink'; ...@@ -9,6 +10,7 @@ import NavLink from 'ui/blocks/navigation/NavLink';
const NavigationMobile = () => { const NavigationMobile = () => {
const { mainNavItems, accountNavItems } = useNavItems(); const { mainNavItems, accountNavItems } = useNavItems();
const router = useRouter(); const router = useRouter();
const isAuth = Boolean(cookies.get(cookies.NAMES.API_TOKEN));
return ( return (
<> <>
...@@ -17,12 +19,14 @@ const NavigationMobile = () => { ...@@ -17,12 +19,14 @@ const NavigationMobile = () => {
{ mainNavItems.map((item) => <NavLink key={ item.text } { ...item } isActive={ router.asPath.startsWith(item.pathname) }/>) } { mainNavItems.map((item) => <NavLink key={ item.text } { ...item } isActive={ router.asPath.startsWith(item.pathname) }/>) }
</VStack> </VStack>
</Box> </Box>
<Box as="nav" mt={ 6 }> { isAuth && (
<VStack as="ul" spacing="2" alignItems="flex-start" overflow="hidden"> <Box as="nav" mt={ 6 }>
{ accountNavItems.map((item) => <NavLink key={ item.text } { ...item } isActive={ router.asPath.startsWith(item.pathname) }/>) } <VStack as="ul" spacing="2" alignItems="flex-start" overflow="hidden">
</VStack> { accountNavItems.map((item) => <NavLink key={ item.text } { ...item } isActive={ router.asPath.startsWith(item.pathname) }/>) }
</Box> </VStack>
<NavFooter/> </Box>
) }
<NavFooter isAuth={ isAuth }/>
</> </>
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment