You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Box } from '@mui/system';
  2. import Head from 'next/head';
  3. import { useState } from 'react';
  4. import FilterSort from '../../components/filter-sort/FilterSort';
  5. import Loader from '../../components/loader/Loader';
  6. import ProductsGrid from '../../components/products-grid/ProductsGrid';
  7. import ProductsHero from '../../components/products-hero/ProductsHero';
  8. import { useInfiniteProducts } from '../../hooks/useInfiniteQuery';
  9. const Products = () => {
  10. const [filter, setFilter] = useState('');
  11. const [sort, setSort] = useState('');
  12. const { data, isLoading, fetchNextPage, hasNextPage } =
  13. useInfiniteProducts(filter);
  14. const handleProductTypeChange = (event) => {
  15. const filterText = event.target.value;
  16. setFilter(filterText);
  17. };
  18. const handleSortChange = (event) => {
  19. const sort = event.target.value;
  20. setSort(sort);
  21. };
  22. if (isLoading) {
  23. return <Loader loading={isLoading} />;
  24. }
  25. return (
  26. <Box
  27. sx={{
  28. display: 'flex',
  29. flexDirection: 'column',
  30. }}
  31. >
  32. <Head>
  33. <title>NextJS template</title>
  34. <meta name="description" content="Random data with pagination..." />
  35. </Head>
  36. <ProductsHero />
  37. <FilterSort
  38. handleProductTypeChange={handleProductTypeChange}
  39. productType={filter}
  40. sort={sort}
  41. handleSortChange={handleSortChange}
  42. />
  43. <ProductsGrid
  44. allProducts={data}
  45. sort={sort}
  46. productType={filter}
  47. fetchNextPage={fetchNextPage}
  48. hasNextPage={hasNextPage}
  49. />
  50. </Box>
  51. );
  52. };
  53. export default Products;