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.
 
 

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