List.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import React, {PureComponent} from "react";
  2. import {connect} from 'react-redux';
  3. import {FeatureTitle, HomeList, BlogList} from "../style";
  4. import {actionCreators} from "../store";
  5. import {Link} from "react-router-dom";
  6. import {getTime} from "../../../lib/public";
  7. import PagInation from '../../../components/PagInation';
  8. const List = (props) => {
  9. const {blogList} = props;
  10. const list = blogList.toJS();
  11. const Class = ['blog-item post-list-show left', 'blog-item post-list-show right'];
  12. return (
  13. <BlogList>
  14. {list.map((item, index) => {
  15. return (
  16. <div className={Class[index % Class.length]} key={index}>
  17. <div className='post-thumb'>
  18. <Link to={'/article/' + item.id}>
  19. <img src={item.thumbnail} alt=""/>
  20. </Link>
  21. </div>
  22. <div className='post-content-wrap'>
  23. <div className='post-content'>
  24. <div className='post-date'>
  25. <i className='iconfont icon-time'/>
  26. 发布于 {getTime(item.createTime)}
  27. </div>
  28. <Link to={'/article/' + item.id} className='post-title'>
  29. <h3>{item.title}</h3>
  30. </Link>
  31. <div className='post-meta'>
  32. <span>
  33. <i className='iconfont icon-attention'/>
  34. {item.views} 热度
  35. </span>
  36. <span className='comments-number'>
  37. <i className='iconfont icon-mark'/>
  38. {item.comments} 评论
  39. </span>
  40. {item.categoryName && <span>
  41. <i className='iconfont icon-file'/>
  42. {item.categoryName}
  43. </span>}
  44. </div>
  45. <div className='float-content'>
  46. <p>{item.summary}</p>
  47. <div className='post-bottom'>
  48. <Link to={'/article/' + item.id}>
  49. <i className='iconfont icon-caidan'/>
  50. </Link>
  51. </div>
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. )
  57. })}
  58. </BlogList>
  59. )
  60. };
  61. class ListWrapper extends PureComponent {
  62. render() {
  63. const {page, finished, loading} = this.props;
  64. return (
  65. <HomeList>
  66. <FeatureTitle>
  67. <h1><i className='iconfont icon-envira'/><span> Discovery</span></h1>
  68. </FeatureTitle>
  69. {List(this.props)}
  70. <PagInation page={page} finished={finished} loading={loading} getList={this.props.getBlogList}/>
  71. </HomeList>
  72. )
  73. }
  74. componentDidMount() {
  75. if (!this.props.isList) {
  76. this.props.getBlogList(1, true);
  77. }
  78. }
  79. }
  80. const mapState = (state) => {
  81. return {
  82. blogList: state.getIn(['home', 'blogList']),
  83. page: state.getIn(['home', 'articlePage']),
  84. finished: state.getIn(['home', 'finished']),
  85. loading: state.getIn(['home', 'loading']),
  86. isList: state.getIn(['home', 'isList']),
  87. }
  88. };
  89. const mapDispatch = (dispatch) => {
  90. return {
  91. getBlogList(page, override) {
  92. dispatch(actionCreators.getBlogList(page, override))
  93. },
  94. }
  95. };
  96. export default connect(mapState, mapDispatch)(ListWrapper);