25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

66 lines
2.3 KiB

  1. import React, { useState, useEffect } from "react";
  2. import Router, { withRouter } from "next/router";
  3. import ReactHtmlParser from "react-html-parser";
  4. // @material-ui/core components
  5. import { makeStyles } from "@material-ui/core/styles";
  6. import ReactPaginate from "react-paginate";
  7. import styles from "assets/jss/nextjs-material-kit/pages/componentsSections/notificationsStyles.js";
  8. const useStyles = makeStyles(styles);
  9. const DataLatestNews = function ({ backend, news, ...props }) {
  10. const [isLoading, setLoading] = useState(false); //State for the loading indicator
  11. const startLoading = () => setLoading(true);
  12. const stopLoading = () => setLoading(false);
  13. useEffect(() => {
  14. //After the component is mounted set router event handlers
  15. Router.events.on("routeChangeStart", startLoading);
  16. Router.events.on("routeChangeComplete", stopLoading);
  17. return () => {
  18. Router.events.off("routeChangeStart", startLoading);
  19. Router.events.off("routeChangeComplete", stopLoading);
  20. };
  21. }, []);
  22. const pagginationHandler = (page) => {
  23. const currentPath = props.router.pathname;
  24. const currentQuery = props.router.query;
  25. currentQuery.page = page.selected + 1;
  26. props.router.push({
  27. pathname: currentPath,
  28. query: currentQuery,
  29. });
  30. };
  31. const classes = useStyles();
  32. const latnews = news.map((data) => {
  33. return (
  34. <div className={classes.section} style={{ padding: "40px" }}>
  35. <div align="center" style={{ marginTop: "-40px" }}>
  36. <h2>{data.title}</h2>
  37. </div>
  38. <br></br>
  39. <br></br>
  40. <div align="center">
  41. <img
  42. src={`${backend}${data.img[0]["url"]}`}
  43. alt="First slide"
  44. className="slick-image"
  45. />
  46. <div>
  47. <br></br>
  48. {data.published_at}
  49. </div>
  50. </div>
  51. <br></br>
  52. <h5 align="justify">{ReactHtmlParser(data.description)}</h5>
  53. </div>
  54. );
  55. });
  56. return <div>{latnews}</div>;
  57. };
  58. export default DataLatestNews;