2024-03-23 22:19:49 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { Box, Center, Flex } from '@chakra-ui/react';
|
|
|
|
import { Link, useLocation, useNavigate } from '@remix-run/react';
|
2023-06-28 01:12:17 +00:00
|
|
|
|
2024-03-23 22:19:49 +00:00
|
|
|
import { Commander } from '../Commander/Commander';
|
|
|
|
import { CommanderV1 } from '../Commander/CommanderV2';
|
|
|
|
import { Icon } from '../Icon/Icon';
|
|
|
|
import { RainbowSkeleton } from '../Skeleton/RainbowSkeleton';
|
|
|
|
import { ProfileDrawer } from './ProfileDrawer';
|
2023-07-07 07:42:14 +00:00
|
|
|
|
|
|
|
export const Nav = (props) => {
|
2024-03-23 22:19:49 +00:00
|
|
|
const [profileDrawerOpen, setProfileDrawerOpen] = React.useState(false);
|
2023-06-29 23:41:06 +00:00
|
|
|
|
2024-03-23 22:19:49 +00:00
|
|
|
const { pathname } = useLocation();
|
2023-08-13 05:53:47 +00:00
|
|
|
|
2024-03-23 22:19:49 +00:00
|
|
|
const navigate = useNavigate();
|
2023-08-13 05:53:47 +00:00
|
|
|
|
2023-06-29 23:41:06 +00:00
|
|
|
const toggleProfileDrawer = React.useCallback(() => {
|
2024-03-23 22:19:49 +00:00
|
|
|
setProfileDrawerOpen(!profileDrawerOpen);
|
|
|
|
}, [profileDrawerOpen]);
|
2023-06-29 23:41:06 +00:00
|
|
|
|
2023-08-15 23:10:13 +00:00
|
|
|
const inEditorMode = React.useMemo(() => {
|
2024-03-23 22:19:49 +00:00
|
|
|
if (pathname.slice(0, 7) === '/editor') {
|
|
|
|
return true;
|
2023-08-15 23:10:13 +00:00
|
|
|
}
|
2024-03-23 22:19:49 +00:00
|
|
|
return false;
|
|
|
|
}, [pathname]);
|
2023-08-15 23:10:13 +00:00
|
|
|
|
2023-08-13 05:53:47 +00:00
|
|
|
const inEditMode = React.useMemo(() => {
|
2024-03-23 22:19:49 +00:00
|
|
|
if (pathname.slice(0, 5) === '/edit') {
|
|
|
|
return true;
|
2023-08-13 05:53:47 +00:00
|
|
|
}
|
2024-03-23 22:19:49 +00:00
|
|
|
return false;
|
|
|
|
}, [pathname]);
|
2023-08-13 05:53:47 +00:00
|
|
|
|
|
|
|
const editorToggleable = React.useMemo(() => {
|
2024-03-23 22:19:49 +00:00
|
|
|
if (pathname.slice(0, 7) === '/things') {
|
|
|
|
return true;
|
|
|
|
} else if (pathname.slice(0, 5) === '/edit') {
|
|
|
|
return true;
|
2023-08-13 05:53:47 +00:00
|
|
|
}
|
2024-03-23 22:19:49 +00:00
|
|
|
return false;
|
|
|
|
}, [pathname]);
|
2023-08-13 05:53:47 +00:00
|
|
|
|
2023-08-15 23:10:13 +00:00
|
|
|
const toggleEdit = React.useCallback(
|
2023-08-13 05:53:47 +00:00
|
|
|
(e) => {
|
|
|
|
// if first characters of pathname are /things replace with /edit
|
|
|
|
// or if first characters of pathname are /edit replace with /things
|
2024-03-23 22:19:49 +00:00
|
|
|
if (pathname.slice(0, 7) === '/things') {
|
|
|
|
const newPathname = pathname.replace('/things', '/edit');
|
|
|
|
navigate(newPathname);
|
|
|
|
} else if (pathname.slice(0, 7) === '/editor') {
|
|
|
|
const newPathname = pathname.replace('/editor', '/things');
|
|
|
|
navigate(newPathname);
|
|
|
|
} else if (pathname.slice(0, 5) === '/edit') {
|
|
|
|
const newPathname = pathname.replace('/edit', '/things');
|
|
|
|
navigate(newPathname);
|
2023-08-13 05:53:47 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
[pathname, navigate]
|
2024-03-23 22:19:49 +00:00
|
|
|
);
|
2023-08-13 05:53:47 +00:00
|
|
|
|
2023-08-15 23:10:13 +00:00
|
|
|
const toggleEditor = React.useCallback(
|
|
|
|
(e) => {
|
|
|
|
// if first characters of pathname are /things replace with /edit
|
|
|
|
// or if first characters of pathname are /edit replace with /things
|
2024-03-23 22:19:49 +00:00
|
|
|
if (pathname.slice(0, 7) === '/editor') {
|
|
|
|
const newPathname = pathname.replace('/editor', '/edit');
|
|
|
|
navigate(newPathname);
|
|
|
|
} else if (pathname.slice(0, 5) === '/edit') {
|
|
|
|
const newPathname = pathname.replace('/edit', '/editor');
|
|
|
|
navigate(newPathname);
|
2023-08-15 23:10:13 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
[pathname, navigate]
|
2024-03-23 22:19:49 +00:00
|
|
|
);
|
2023-08-15 23:10:13 +00:00
|
|
|
|
2023-06-28 01:12:17 +00:00
|
|
|
return (
|
|
|
|
<>
|
2024-03-23 22:19:49 +00:00
|
|
|
<Box position="fixed" zIndex={9999} top={0} right={0} left={0} maxWidth="100vw">
|
2023-07-01 09:46:36 +00:00
|
|
|
<Flex
|
2023-07-07 07:42:14 +00:00
|
|
|
as="nav"
|
|
|
|
position="relative"
|
|
|
|
alignItems="center"
|
|
|
|
justifyContent="center"
|
|
|
|
flexDirection="row"
|
|
|
|
width="100%"
|
|
|
|
maxWidth="100%"
|
|
|
|
marginY={1}
|
2023-08-13 05:53:47 +00:00
|
|
|
paddingX="18px"
|
|
|
|
paddingY="14px"
|
2023-07-04 08:05:08 +00:00
|
|
|
// bg='white'
|
|
|
|
// boxShadow={'0px 0px 10px rgba(0,0,0,0.1)'}
|
2023-07-01 09:46:36 +00:00
|
|
|
>
|
2024-03-23 22:19:49 +00:00
|
|
|
<Center className="nav-left-section" display={['none', 'flex']} height="100%" marginRight="auto">
|
2023-08-13 05:53:47 +00:00
|
|
|
<Center transform="scaleX(-100%)" cursor="pointer">
|
|
|
|
<Link to="/">
|
2024-03-23 22:19:49 +00:00
|
|
|
<Icon size="12px" name="🦄"></Icon>
|
2023-08-13 05:53:47 +00:00
|
|
|
</Link>
|
|
|
|
</Center>
|
2023-08-09 00:43:18 +00:00
|
|
|
</Center>
|
2023-08-14 09:00:42 +00:00
|
|
|
<CommanderV1 global id="nav" rainbow={false}></CommanderV1>
|
2024-03-23 22:19:49 +00:00
|
|
|
<Center className="nav-right-section" columnGap={[3, 8]} height="100%" marginLeft="auto">
|
2023-08-16 00:21:37 +00:00
|
|
|
{inEditMode && (
|
2023-08-13 05:53:47 +00:00
|
|
|
<Center
|
2023-08-15 23:10:13 +00:00
|
|
|
// transform="scaleX(-100%)"
|
2023-08-13 05:53:47 +00:00
|
|
|
cursor="pointer"
|
|
|
|
onClick={toggleEditor}
|
2023-08-15 23:10:13 +00:00
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
chakras={{
|
2024-03-23 22:19:49 +00:00
|
|
|
opacity: inEditorMode ? 1 : 0.3
|
2023-08-15 23:10:13 +00:00
|
|
|
}}
|
|
|
|
size="12px"
|
2024-03-23 22:19:49 +00:00
|
|
|
name="👀"
|
2023-08-15 23:10:13 +00:00
|
|
|
></Icon>
|
|
|
|
{/* <Icon
|
|
|
|
size="12px"
|
|
|
|
name={inEditorMode ? "glowing star" : "star"}
|
|
|
|
></Icon> */}
|
|
|
|
</Center>
|
|
|
|
)}
|
|
|
|
{editorToggleable && (
|
2024-03-23 22:19:49 +00:00
|
|
|
<Center transform="scaleX(-100%)" cursor="pointer" onClick={toggleEdit}>
|
2023-08-13 05:53:47 +00:00
|
|
|
<Icon
|
|
|
|
chakras={{
|
2024-03-23 22:19:49 +00:00
|
|
|
opacity: inEditMode ? 1 : 0.3
|
2023-08-13 05:53:47 +00:00
|
|
|
}}
|
|
|
|
size="12px"
|
2024-03-23 22:19:49 +00:00
|
|
|
name="🎨"
|
2023-08-13 05:53:47 +00:00
|
|
|
></Icon>
|
|
|
|
{/* <Icon
|
|
|
|
size="12px"
|
|
|
|
name={inEditMode ? "glowing star" : "star"}
|
|
|
|
></Icon> */}
|
|
|
|
</Center>
|
|
|
|
)}
|
2024-03-23 22:19:49 +00:00
|
|
|
<Center transform={['', 'scaleX(-100%)']} cursor="pointer">
|
2024-04-20 13:43:55 +00:00
|
|
|
<Link to="/login">
|
|
|
|
<Icon size="12px" name="🌈"></Icon>
|
|
|
|
</Link>
|
2023-08-13 05:53:47 +00:00
|
|
|
</Center>
|
2024-03-23 22:19:49 +00:00
|
|
|
<Center display={['flex', 'none']} cursor="pointer">
|
2023-08-14 00:51:00 +00:00
|
|
|
<Link to="/">
|
2024-03-23 22:19:49 +00:00
|
|
|
<Icon size="12px" name="🦄"></Icon>
|
2023-08-14 00:51:00 +00:00
|
|
|
</Link>
|
|
|
|
</Center>
|
2023-08-09 00:43:18 +00:00
|
|
|
</Center>
|
|
|
|
{/* <RainbowSkeleton
|
2023-07-07 07:42:14 +00:00
|
|
|
marginLeft="auto"
|
|
|
|
width="25px"
|
|
|
|
height="25px"
|
|
|
|
cursor="pointer"
|
2023-07-01 09:46:36 +00:00
|
|
|
onClick={toggleProfileDrawer}
|
2023-07-07 07:42:14 +00:00
|
|
|
background="rgba(0,0,0,0.1)"
|
2023-07-01 09:46:36 +00:00
|
|
|
sx={{}}
|
2023-07-07 07:42:14 +00:00
|
|
|
borderRadius="999px"
|
2023-08-09 00:43:18 +00:00
|
|
|
></RainbowSkeleton> */}
|
2023-07-01 09:46:36 +00:00
|
|
|
{/* <RainbowSkeleton w='40px' ml='auto' mr={"4px"}></RainbowSkeleton>
|
|
|
|
<RainbowSkeleton></RainbowSkeleton> */}
|
|
|
|
</Flex>
|
|
|
|
</Box>
|
2023-06-29 23:41:06 +00:00
|
|
|
{/* <ProfileDrawer isOpen={profileDrawerOpen}></ProfileDrawer> */}
|
2023-06-28 01:12:17 +00:00
|
|
|
</>
|
2024-03-23 22:19:49 +00:00
|
|
|
);
|
|
|
|
};
|