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.

ProductsGrid.tsx 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { Container, Grid } from '@mui/material';
  2. import { Box } from '@mui/system';
  3. import { ProductDataDB } from '../../utils/interface/productInterface';
  4. import LoadMore from '../buttons/load-more/LoadMore';
  5. import GridItem from '../grid-item/GridItem';
  6. import ProductCard from '../product-card/ProductCard';
  7. interface PageProps {
  8. message: string;
  9. next: string;
  10. prevous: string;
  11. product: ProductDataDB[];
  12. productCount: number;
  13. }
  14. interface ProductsProps {
  15. pages: PageProps[];
  16. }
  17. interface Props {
  18. allProducts: ProductsProps
  19. hasNextPage: boolean;
  20. isFetchingNextPage: boolean;
  21. fetchNextPage: () => void;
  22. }
  23. const ProductsGrid: React.FC<Props> = ({
  24. allProducts,
  25. hasNextPage,
  26. fetchNextPage,
  27. isFetchingNextPage,
  28. }) => {
  29. const dataToDisplay = allProducts.pages.map((page) =>
  30. page.product.map((item) => (
  31. <GridItem key={item._id}>
  32. <ProductCard product={item} />
  33. </GridItem>
  34. ))
  35. );
  36. return (
  37. <Container
  38. sx={{
  39. mt: 10,
  40. }}
  41. >
  42. <Grid container spacing={2}>
  43. {dataToDisplay}
  44. </Grid>
  45. <Box textAlign="center" mt={-5} mb={5}>
  46. {hasNextPage && (
  47. <LoadMore
  48. fetchNextPage={fetchNextPage}
  49. isFetchingNextPage={isFetchingNextPage}
  50. hasNextPage={hasNextPage}
  51. />
  52. )}
  53. </Box>
  54. </Container>
  55. );
  56. };
  57. export default ProductsGrid;