Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ProductsGrid.jsx 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { Button, Container, Grid } from '@mui/material';
  2. import CircularProgress from '@mui/material/CircularProgress';
  3. import { Box } from '@mui/system';
  4. import Image from 'next/image';
  5. import ProductCard from '../product-card/ProductCard';
  6. const ProductsGrid = ({
  7. allProducts,
  8. hasNextPage,
  9. fetchNextPage,
  10. isFetchingNextPage,
  11. }) => {
  12. const dataToDisplay = allProducts.pages.map((page) =>
  13. page.product.map((item) => (
  14. <Grid key={item._id} item md={4} sm={6} xs={12} sx={{ mb: '100px' }}>
  15. <ProductCard product={item} />
  16. </Grid>
  17. ))
  18. );
  19. return (
  20. <Container
  21. sx={{
  22. mt: 10,
  23. }}
  24. >
  25. <Grid container spacing={2}>
  26. {dataToDisplay}
  27. </Grid>
  28. <Box textAlign="center" mt={-5} mb={5}>
  29. {hasNextPage && (
  30. <Button
  31. onClick={fetchNextPage}
  32. startIcon={
  33. !isFetchingNextPage && (
  34. <Image
  35. src="/images/arrow.svg"
  36. alt="arrow down"
  37. width={29}
  38. height={29}
  39. />
  40. )
  41. }
  42. sx={{
  43. backgroundColor: 'primary.main',
  44. height: 50,
  45. width: 150,
  46. color: 'white',
  47. ':hover': {
  48. bgcolor: 'primary.main', // theme.palette.primary.main
  49. color: 'white',
  50. },
  51. }}
  52. >
  53. {isFetchingNextPage && (
  54. <CircularProgress
  55. style={{
  56. color: '#fff',
  57. width: '29px',
  58. height: '29px',
  59. marginRight: '20px',
  60. }}
  61. />
  62. )}
  63. {isFetchingNextPage
  64. ? 'Loading...'
  65. : hasNextPage
  66. ? 'Load More'
  67. : 'Nothing more to load'}
  68. </Button>
  69. )}
  70. </Box>
  71. </Container>
  72. );
  73. };
  74. export default ProductsGrid;