-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProductsContainer.jsx
60 lines (56 loc) · 1.63 KB
/
ProductsContainer.jsx
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
import { useLoaderData } from 'react-router-dom';
import ProductsGrid from './ProductsGrid';
import ProductsList from './ProductsList';
import { useState } from 'react';
import { BsFillGridFill, BsList } from 'react-icons/bs';
const ProductsContainer = () => {
const { meta } = useLoaderData();
const totalProducts = meta.pagination.total;
const [layout, setLayout] = useState('grid');
const setActiveStyles = (pattern) => {
return `text-xl btn btn-circle btn-sm ${
pattern === layout
? 'btn-primary text-primary-content'
: 'btn-ghost text-based-content'
}`;
};
return (
<>
{/* HEADER */}
<div className='flex justify-between items-center mt-8 border-b border-base-300 pb-5'>
<h4 className='font-medium text-md'>
{totalProducts} product{totalProducts > 1 && 's'}
</h4>
<div className='flex gap-x-2'>
<button
type='button'
onClick={() => setLayout('grid')}
className={setActiveStyles('grid')}
>
<BsFillGridFill />
</button>
<button
type='button'
onClick={() => setLayout('list')}
className={setActiveStyles('list')}
>
<BsList />
</button>
</div>
</div>
{/* PRODUCTS */}
<div>
{totalProducts === 0 ? (
<h5 className='text-2xl mt-16'>
Sorry, no products matched your search...
</h5>
) : layout === 'grid' ? (
<ProductsGrid />
) : (
<ProductsList />
)}
</div>
</>
);
};
export default ProductsContainer;