File size: 2,803 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
import {
   Box,
   Heading,
   HStack,
   Input,
   InputGroup,
   InputRightElement,
   Select,
} from '@chakra-ui/react';
import { nanoid } from '@reduxjs/toolkit';
import React from 'react';
import { FiSearch } from 'react-icons/fi';
import { useLocation } from 'react-router-dom';
import { SecondaryBtn } from '../../utils/Buttons';

const Header = ({
   readingCount,
   archiveCount,
   allTags,
   selectedTagName,
   handleClickTag,
   handleSearch,
   toggleViewArchive,
}) => {
   const location = useLocation();

   const handleSelectOption = ({ target }) => {
      handleClickTag(target.value);
   };

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

   const title = query
      ? `Archive (${archiveCount})`
      : `Reading list (${readingCount})`;

   return (
      <Box px={{ base: '.5rem', md: '0' }}>
         <HStack
            justify='space-between'
            display={{ base: 'flex', md: 'none' }}
            mb='.5rem'
         >
            <Heading fontSize={['1.5rem', '1.5rem', '2rem']}>{title}</Heading>

            <SecondaryBtn onClick={toggleViewArchive}>
               {query ? 'View reading list' : 'View archive'}
            </SecondaryBtn>
         </HStack>

         <HStack justify='space-between'>
            <Heading
               fontSize={['1.5rem', '1.5rem', '2rem']}
               display={{ base: 'none', md: 'block' }}
            >
               {title}
            </Heading>

            <HStack
               w={['100%', '100%', 'auto']}
               ms={{ base: '0 !important', md: '.5rem' }}
            >
               <SecondaryBtn
                  display={{ base: 'none', md: 'block' }}
                  onClick={toggleViewArchive}
               >
                  {query ? 'View Reading List' : 'View archive'}
               </SecondaryBtn>

               <InputGroup
                  h='39px'
                  w={{ base: '100%', md: '250px' }}
                  ms={{ base: '0 !important', md: '0.5rem !important' }}
               >
                  <Input placeholder='Search...' onChange={handleSearch} />
                  <InputRightElement
                     children={<FiSearch size={23} color='gray' />}
                  />
               </InputGroup>
            </HStack>
         </HStack>

         <Box mt={2}>
            <Select
               display={['block', 'block', 'none']}
               onChange={handleSelectOption}
               value={selectedTagName}
            >
               {allTags.map((item) => (
                  <option key={nanoid()} value={item.tagName}>
                     {item.tagName}
                  </option>
               ))}
            </Select>
         </Box>
      </Box>
   );
};

export default Header;