File size: 1,659 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
import React from 'react';
import { Flex, useColorModeValue } from '@chakra-ui/react';
import styled from '@emotion/styled';
import { useLocation } from 'react-router-dom';

const SortNavbar = ({ handleClickNavItem }) => {
   const location = useLocation();
   const activeLinkColor = useColorModeValue('#090909', '#f9f9f9');

   const NavItem = styled.div`
      padding: 0.5rem 1rem;
      border-radius: 5px;
      font-size: 17px;
      cursor: pointer;
      color: ${useColorModeValue('#575757', '#bdbdbd')};

      &:hover {
         background-color: ${useColorModeValue(
            'rgb(255 255 255)',
            'rgb(23 23 23)'
         )};
         color: ${useColorModeValue('rgb(47 58 178)', 'rgb(165, 180, 252)')};
      }
   `;

   const activeLink = (isActive) => {
      return isActive
         ? {
              color: activeLinkColor,
              fontWeight: '600',
           }
         : {};
   };

   const queryParam = new URLSearchParams(location.search);
   const sort = queryParam.get('sort');

   return (
      <Flex mb='.5rem' ms={{ base: '.2rem', md: 0 }}>
         <NavItem
            onClick={() => handleClickNavItem('relevant')}
            style={activeLink(sort === null)}
         >
            Relevant
         </NavItem>
         <NavItem
            onClick={() => handleClickNavItem('latest')}
            style={activeLink(sort === 'latest')}
         >
            Latest
         </NavItem>
         <NavItem
            onClick={() => handleClickNavItem('top')}
            style={activeLink(sort === 'top')}
         >
            Top
         </NavItem>
      </Flex>
   );
};

export default SortNavbar;