通用评论

index.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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({ page: this.props.app.page });
  14. }
  15. renderPagination() {
  16. const {
  17. list,
  18. total,
  19. page,
  20. pageType,
  21. isNoMoreComment,
  22. sGetComment,
  23. onPageChange
  24. } = this.props.app;
  25. if (pageType === "more") {
  26. if (!isNoMoreComment && list.length !== total) {
  27. return (
  28. <div
  29. className="comment-list-show-more"
  30. onClick={() => {
  31. sGetComment({ page: page + 1 });
  32. onPageChange(page + 1);
  33. }}
  34. >
  35. <span>查看更多评论</span>
  36. </div>
  37. );
  38. } else {
  39. return null;
  40. }
  41. } else if (pageType === "pagination") {
  42. return (
  43. <div className="comment-list-pagination">
  44. <Pagination
  45. pageSize={LIMIT}
  46. current={page}
  47. total={total}
  48. onChange={p => {
  49. sGetComment({ page: p });
  50. onPageChange(p);
  51. }}
  52. />
  53. </div>
  54. );
  55. }
  56. }
  57. render() {
  58. const { list, total, loading } = this.props.app;
  59. const spinning = Boolean(
  60. loading.sGetComment || loading.sCommentFavor || loading.sReplyFavor
  61. );
  62. return (
  63. <div>
  64. <Spin spinning={spinning}>
  65. <div>共 {total} 条评论</div>
  66. {list.map(item => (
  67. <CommentBox content={item} key={item.id} commentId={item.id} />
  68. ))}
  69. {this.renderPagination()}
  70. </Spin>
  71. </div>
  72. );
  73. }
  74. }
  75. CommentList.propTypes = {};
  76. export default Comment(CommentList);