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.

ProductsContent.tsx 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { Box } from '@mui/system';
  2. import Head from 'next/head';
  3. import { useState } from 'react';
  4. import { useInfiniteProducts } from '../../hooks/useInfiniteQuery';
  5. import FilterSort from '../filter-sort/FilterSort';
  6. import LoadingSpinner from '../loader/basic-spinner/LoadSpinner';
  7. import ProductsGrid from '../products-grid/ProductsGrid';
  8. import ProductsHero from '../products-hero/ProductsHero';
  9. const ProductsContent = () => {
  10. const [filter, setFilter] = useState('');
  11. const [sort, setSort] = useState('');
  12. const { data, isLoading, fetchNextPage, hasNextPage, isFetchingNextPage } =
  13. useInfiniteProducts(filter, sort);
  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. return (
  23. <Box
  24. sx={{
  25. display: 'flex',
  26. flexDirection: 'column',
  27. }}
  28. >
  29. <Head>
  30. <title>Coffee Shop</title>
  31. <meta name="description" content="Random data with pagination..." />
  32. </Head>
  33. <ProductsHero />
  34. <FilterSort
  35. handleProductTypeChange={handleProductTypeChange}
  36. productType={filter}
  37. sort={sort}
  38. handleSortChange={handleSortChange}
  39. />
  40. {isLoading ? (
  41. <LoadingSpinner />
  42. ) : (
  43. <ProductsGrid
  44. allProducts={data}
  45. sort={sort}
  46. productType={filter}
  47. fetchNextPage={fetchNextPage}
  48. hasNextPage={hasNextPage}
  49. isFetchingNextPage={isFetchingNextPage}
  50. />
  51. )}
  52. </Box>
  53. );
  54. };
  55. export default ProductsContent;