Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ProductsContent.tsx 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. import { SelectChangeEvent } from "@mui/material";
  10. const ProductsContent = () => {
  11. const [filter, setFilter] = useState<string>('');
  12. const [sort, setSort] = useState<string>('');
  13. const { data, isLoading, fetchNextPage, hasNextPage, isFetchingNextPage } =
  14. useInfiniteProducts(filter, sort);
  15. const handleProductTypeChange = () => {
  16. return (event: SelectChangeEvent) => {
  17. const filterText = event.target.value;
  18. setFilter(filterText);
  19. }
  20. };
  21. const handleSortChange = () => {
  22. return (event: SelectChangeEvent) => {
  23. const sort = event.target.value;
  24. setSort(sort);
  25. }
  26. };
  27. return (
  28. <Box
  29. sx={{
  30. display: 'flex',
  31. flexDirection: 'column',
  32. }}
  33. >
  34. <Head>
  35. <title>Coffee Shop</title>
  36. <meta name="description" content="Random data with pagination..." />
  37. </Head>
  38. <ProductsHero />
  39. <FilterSort
  40. handleProductTypeChange={handleProductTypeChange}
  41. productType={filter}
  42. sort={sort}
  43. handleSortChange={handleSortChange}
  44. />
  45. {isLoading ? (
  46. <LoadingSpinner />
  47. ) : (
  48. <ProductsGrid
  49. allProducts={data}
  50. fetchNextPage={fetchNextPage}
  51. hasNextPage={hasNextPage}
  52. isFetchingNextPage={isFetchingNextPage}
  53. />
  54. )}
  55. </Box>
  56. );
  57. };
  58. export default ProductsContent;