Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

95 wiersze
2.9 KiB

  1. import React, { useState, useEffect } from 'react';
  2. import Router, { withRouter } from 'next/router'
  3. // @material-ui/core components
  4. import { makeStyles } from "@material-ui/core/styles";
  5. import ReactPaginate from 'react-paginate';
  6. // component
  7. import styles from "assets/jss/nextjs-material-kit/pages/componentsSections/notificationsStyles.js";
  8. import Paper from '@material-ui/core/Paper';
  9. import Grid from '@material-ui/core/Grid';
  10. import GridContainer from "components/Grid/GridContainer.js";
  11. import Card from "components/Card/Card.js";
  12. import CardBody from "components/Card/CardBody.js";
  13. import Button from "components/CustomButtons/Button.js";
  14. import Paginations from "components/Pagination/Pagination.js";
  15. const useStyles = makeStyles(styles);
  16. const DataLatestNews = function ({ backend, news, ...props }) {
  17. const [isLoading, setLoading] = useState(false); //State for the loading indicator
  18. const startLoading = () => setLoading(true);
  19. const stopLoading = () => setLoading(false);
  20. useEffect(() => { //After the component is mounted set router event handlers
  21. Router.events.on('routeChangeStart', startLoading);
  22. Router.events.on('routeChangeComplete', stopLoading);
  23. return () => {
  24. Router.events.off('routeChangeStart', startLoading);
  25. Router.events.off('routeChangeComplete', stopLoading);
  26. }
  27. }, [])
  28. const pagginationHandler = (page) => {
  29. const currentPath = props.router.pathname;
  30. const currentQuery = props.router.query;
  31. currentQuery.page = page.selected + 1;
  32. props.router.push({
  33. pathname: currentPath,
  34. query: currentQuery,
  35. });
  36. };
  37. const classes = useStyles();
  38. const latnews = news.map((data) => {
  39. return (
  40. <Grid align="center" style={{padding:"30px", marginTop:"-50px"}}>
  41. <Card style={{width: "20rem"}}>
  42. <img
  43. style={{height: "180px", width: "100%", display: "block"}}
  44. className={classes.imgCardTop}
  45. src={`${backend}${data.img[0]["url"]}`}
  46. />
  47. <CardBody>
  48. {/* <h4 className={classes.cardTitle}>{data.title}</h4> */}
  49. <p>{data.title}</p>
  50. <Button color="info" onclick="myFunction()" id="myBtn">Read More</Button>
  51. </CardBody>
  52. </Card>
  53. </Grid>
  54. );
  55. })
  56. return (
  57. <div className={classes.section} id="notifications">
  58. <div align="center">
  59. <h2>Latest News</h2>
  60. </div>
  61. <div>
  62. <GridContainer justify="center">
  63. {latnews}
  64. {latnews}
  65. </GridContainer>
  66. </div>
  67. <div align="center">
  68. <Paginations
  69. color="info"
  70. pages={[
  71. { text: 1 },
  72. { text: "..." },
  73. { text: 5 },
  74. { text: 6 },
  75. { active: true, text: 7 },
  76. { text: 8 },
  77. { text: 9 },
  78. { text: "..." },
  79. { text: 12 }
  80. ]}
  81. />
  82. </div>
  83. </div>
  84. );
  85. }
  86. export default DataLatestNews;