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.7KB

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