通用评论

1
  1. {"version":3,"sources":["../../../src/components/CommentBox/index.js"],"names":["CommentBox","props","state","showReply","page","handleToggleReply","bind","handleGetMoreReply","renderReplies","setState","commentId","app","sGetReply","replies","replyCount","isNoMoreReply","length","len","marginLeft","map","item","index","id","float","content","reply_count","Component","propTypes","PropTypes","string","isRequired","defaultProps"],"mappings":";;;;;;;;;;;;;;AAAA;;;;AACA;;;;AAEA;;;;AACA;;;;AACA;;;;;;;;;;IAEMA,U;;;AACJ,sBAAYC,KAAZ,EAAmB;AAAA;;AAAA,wHACXA,KADW;;AAEjB,UAAKC,KAAL,GAAa;AACXC,iBAAW,IADA;AAEXC,YAAM;AAFK,KAAb;;AAKA,UAAKC,iBAAL,GAAyB,MAAKA,iBAAL,CAAuBC,IAAvB,OAAzB;AACA,UAAKC,kBAAL,GAA0B,MAAKA,kBAAL,CAAwBD,IAAxB,OAA1B;AACA,UAAKE,aAAL,GAAqB,MAAKA,aAAL,CAAmBF,IAAnB,OAArB;AATiB;AAUlB;;AAED;;;;;;;wCAGoB;AAClB,WAAKG,QAAL,CAAc,EAAEN,WAAW,CAAC,KAAKD,KAAL,CAAWC,SAAzB,EAAd;AACD;;AAED;;;;;;;uCAImBO,S,EAAW;AAC5B;AAD4B,UAEpBN,IAFoB,GAEX,KAAKF,KAFM,CAEpBE,IAFoB;;AAG5B,WAAKH,KAAL,CAAWU,GAAX,CAAeC,SAAf,CAAyB,EAAEF,oBAAF,EAAaN,UAAb,EAAzB;AACA,WAAKK,QAAL,CAAc,EAAEL,MAAMA,OAAO,CAAf,EAAd;AACD;;AAED;;;;;;;;;kCAMcS,O,EAASC,U,EAAYC,a,EAAe;AAAA;;AAAA,UACxCL,SADwC,GAC1B,KAAKT,KADqB,CACxCS,SADwC;AAAA,UAExCP,SAFwC,GAE1B,KAAKD,KAFqB,CAExCC,SAFwC;;AAGhD,UAAIA,aAAaU,OAAb,IAAwBA,QAAQG,MAApC,EAA4C;AAC1C,YAAMC,MAAMJ,QAAQG,MA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AQX,OADT,EAECW,QAAQC,WAFT,EAGCD,QAAQT,aAHT;AARH,OADF;AAgBD;;;;EA7GsBW,gB;;AAgHzB1B,WAAW2B,SAAX,GAAuB;AACrBjB,aAAWkB,oBAAUC,MAAV,CAAiBC;AADP,CAAvB;;AAIA9B,WAAW+B,YAAX,GAA0B,EAA1B;;kBAEe,uBAAQ/B,UAAR,C","file":"index.js","sourcesContent":["import React, { Component } from 'react';\nimport PropTypes from 'prop-types';\nimport { Icon } from 'antd';\nimport Comment from '../../Comment';\nimport ContentItem from './../ContentItem';\nimport './index.css';\n\nclass CommentBox extends Component {\n constructor(props) {\n super(props);\n this.state = {\n showReply: true,\n page: 1,\n };\n\n this.handleToggleReply = this.handleToggleReply.bind(this);\n this.handleGetMoreReply = this.handleGetMoreReply.bind(this);\n this.renderReplies = this.renderReplies.bind(this);\n }\n\n /**\n * 切换是否显示回复列表\n */\n handleToggleReply() {\n this.setState({ showReply: !this.state.showReply });\n }\n\n /**\n * 获取更多评论\n * @param {string} commentId comment id\n */\n handleGetMoreReply(commentId) {\n // 从第一页开始获取评论\n const { page } = this.state;\n this.props.app.sGetReply({ commentId, page });\n this.setState({ page: page + 1 });\n }\n\n /**\n * 渲染回复 DOM\n * @param {array} replies 回复列表\n * @param {number} replies 回复的数量\n * @param {boolean} isNoMoreReply 是否没有更多回复\n */\n renderReplies(replies, replyCount, isNoMoreReply) {\n const { commentId } = this.props;\n const { showReply } = this.state;\n if (showReply && replies && replies.length) {\n const len = replies.length;\n return (\n <div style={{ marginLeft: 50 }}>\n {replies.map((item, index) => {\n if (index === len - 1) {\n return [\n <ContentItem\n commentId={commentId}\n replyId={item.id}\n key={item.id}\n content={item}\n action=\"replyToReply\" // 回复的回复\n />,\n <div className=\"comment-more-box\" key=\"show_more_button\">\n {!isNoMoreReply &&\n replyCount !== len && (\n <span\n className=\"comment-show-more\"\n onClick={() => this.handleGetMoreReply(commentId)}\n >\n 查看更多回复\n </span>\n )}\n\n <a\n style={{ float: 'right' }}\n onClick={this.handleToggleReply}\n >\n <Icon type=\"up\" /> 收起回复\n </a>\n </div>,\n ];\n }\n return (\n <ContentItem\n commentId={commentId}\n replyId={item.id}\n key={item.id}\n content={item}\n action=\"replyToReply\" // 评论的回复\n />\n );\n })}\n </div>\n );\n }\n return null;\n }\n\n render() {\n const { content } = this.props;\n const { showReply } = this.state;\n return (\n <div>\n <ContentItem\n content={content}\n onShowReply={this.handleToggleReply}\n showReply={showReply}\n commentId={content.id}\n action=\"reply\" // 评论的回复\n />\n {this.renderReplies(\n content.replies,\n content.reply_count,\n content.isNoMoreReply\n )}\n </div>\n );\n }\n}\n\nCommentBox.propTypes = {\n commentId: PropTypes.string.isRequired,\n};\n\nCommentBox.defaultProps = {};\n\nexport default Comment(CommentBox);\n"]}