File size: 3,661 Bytes
f5071ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
import React from 'react';
import { Box, HStack, Link } from '@chakra-ui/react';
import { useAuth } from '../../context/auth';
import { useLocation, useNavigate } from 'react-router-dom';
import { useSelector } from 'react-redux';
import Hero from '../Hero';
import SideMenuItem from '../../utils/SideMenuItem';
import TagMenu from './TagMenu';
import {
aboutIcon,
contactIcon,
tagIcon,
homeIcon,
readingListIcon,
FAQIcon,
} from '../../assets/icons';
import { SecondaryBtn } from '../../utils/Buttons';
import {
GrFacebook,
GrGithub,
GrInstagram,
GrLinkedin,
GrTwitter,
} from 'react-icons/gr';
const SocialLinkIcon = ({ children, href }) => {
return (
<Link href={href} target='_blank'>
<SecondaryBtn>{children}</SecondaryBtn>
</Link>
);
};
const Menu = ({ onClose, heroPadding }) => {
const user = useAuth();
const navigate = useNavigate();
const location = useLocation();
const { transformedData } = useSelector((state) => state.transformedData);
let savedPosts = [];
if (transformedData) {
savedPosts = transformedData.filter(
(postItem) =>
postItem.saved?.includes(user?.userId) &&
!postItem.archived?.includes(user?.userId)
);
}
const handleClickHome = () => {
onClose && onClose();
if (location.pathname !== '/') {
navigate('/');
}
window.scrollTo(0, 0);
};
const handleClickMenu = (route) => {
onClose && onClose();
navigate(`/${route}`);
};
return (
<Box>
{!user && (
<Box className='shadow' borderRadius='5px' mb='.7rem'>
<Hero
btnWidth='100%'
onClose={onClose ? onClose : () => {}}
p={heroPadding}
/>
</Box>
)}
<SideMenuItem icon={homeIcon} title='Home' onClick={handleClickHome} />
{user && (
<SideMenuItem
icon={readingListIcon}
savedPostsCount={savedPosts.length}
title='Reading List'
onClick={() => handleClickMenu('readinglist')}
/>
)}
<SideMenuItem
icon={tagIcon}
title='Tags'
onClick={() => handleClickMenu('tags')}
/>
<SideMenuItem
icon={FAQIcon}
title='FAQ'
onClick={() => handleClickMenu('faq')}
/>
<SideMenuItem
icon={contactIcon}
title='Contact'
onClick={() => handleClickMenu('contact')}
/>
<SideMenuItem
icon={aboutIcon}
title='About'
onClick={() => handleClickMenu('about')}
/>
<HStack justify='' my='3'>
<SocialLinkIcon href='https://twitter.com/zwelHtetYan2'>
<GrTwitter size={22} />
</SocialLinkIcon>
<SocialLinkIcon href='https://www.facebook.com/zwel.h.yan/'>
<GrFacebook size={20} />
</SocialLinkIcon>
<SocialLinkIcon href='https://github.com/zwelhtetyan'>
<GrGithub size={23} />
</SocialLinkIcon>
<SocialLinkIcon href='https://www.instagram.com/zwel.h.y/'>
<GrInstagram size={20} />
</SocialLinkIcon>
<SocialLinkIcon href='https://www.linkedin.com/in/zwelhtetyan/ '>
<GrLinkedin size={20} />
</SocialLinkIcon>
</HStack>
{/* tags */}
<TagMenu userId={user?.userId} onClose={onClose} />
</Box>
);
};
export default Menu;
|