通用评论

index.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import React, { Component } from "react";
  2. import { Spin, Pagination } from "antd";
  3. import Comment from "../../Comment";
  4. import CommentBox from "../CommentBox";
  5. import "./index.css";
  6. import { LIMIT } from "../../constant";
  7. class CommentList extends Component {
  8. constructor(props) {
  9. super(props);
  10. this.state = {};
  11. }
  12. componentWillMount() {
  13. this.props.app.sGetComment();
  14. }
  15. renderPagination() {
  16. const {
  17. list,
  18. total,
  19. page,
  20. pageType,
  21. isNoMoreComment,
  22. sGetComment
  23. } = this.props.app;
  24. if (pageType === "more") {
  25. if (!isNoMoreComment && list.length !== total) {
  26. return (
  27. <div
  28. className="comment-list-show-more"
  29. onClick={() => sGetComment({ page: page + 1 })}
  30. >
  31. <span>查看更多评论</span>
  32. </div>
  33. );
  34. } else {
  35. return null;
  36. }
  37. } else if (pageType === "pagination") {
  38. return (
  39. <div className="comment-list-pagination">
  40. <Pagination
  41. pageSize={LIMIT}
  42. current={page}
  43. total={total}
  44. onChange={p => {
  45. sGetComment({ page: p });
  46. }}
  47. />
  48. </div>
  49. );
  50. }
  51. }
  52. render() {
  53. const { list, total, loading } = this.props.app;
  54. const spinning = Boolean(
  55. loading.sGetComment || loading.sCommentFavor || loading.sReplyFavor
  56. );
  57. return (
  58. <div>
  59. <Spin spinning={spinning}>
  60. <div>共 {total} 条评论</div>
  61. {list.map(item => (
  62. <CommentBox content={item} key={item.id} commentId={item.id} />
  63. ))}
  64. {this.renderPagination()}
  65. </Spin>
  66. </div>
  67. );
  68. }
  69. }
  70. CommentList.propTypes = {};
  71. export default Comment(CommentList);