Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

index.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 LoadingSpinner from '../../components/loader/basic-spinner/LoadSpinner';
  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, 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>NextJS template</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 Products;