通用评论

EditComment.js 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _modal = require("antd/es/modal");
  6. var _modal2 = _interopRequireDefault(_modal);
  7. var _icon = require("antd/es/icon");
  8. var _icon2 = _interopRequireDefault(_icon);
  9. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  10. require("antd/es/modal/style/css");
  11. require("antd/es/icon/style/css");
  12. var _react = require("react");
  13. var _react2 = _interopRequireDefault(_react);
  14. var _propTypes = require("prop-types");
  15. var _propTypes2 = _interopRequireDefault(_propTypes);
  16. var _reactIntlUniversal = require("react-intl-universal");
  17. var _reactIntlUniversal2 = _interopRequireDefault(_reactIntlUniversal);
  18. var _CommentInput = require("../CommentInput");
  19. var _CommentInput2 = _interopRequireDefault(_CommentInput);
  20. var _Editor = require("../Editor");
  21. var _Editor2 = _interopRequireDefault(_Editor);
  22. var _constant = require("../../constant");
  23. require("./EditComment.css");
  24. var _Comment = require("../../Comment");
  25. var _Comment2 = _interopRequireDefault(_Comment);
  26. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  27. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  28. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  29. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  30. var EditComment = function (_React$Component) {
  31. _inherits(EditComment, _React$Component);
  32. function EditComment(props) {
  33. _classCallCheck(this, EditComment);
  34. var _this = _possibleConstructorReturn(this, (EditComment.__proto__ || Object.getPrototypeOf(EditComment)).call(this, props));
  35. _this.handleSubmit = _this.handleSubmit.bind(_this);
  36. _this.state = {
  37. value: _this.getInitValue(props).value,
  38. fileList: _this.getInitValue(props).fileList
  39. };
  40. return _this;
  41. }
  42. _createClass(EditComment, [{
  43. key: "handleSubmit",
  44. value: function handleSubmit(_ref) {
  45. var _ref$text = _ref.text,
  46. text = _ref$text === undefined ? "" : _ref$text,
  47. _ref$files = _ref.files,
  48. files = _ref$files === undefined ? [] : _ref$files;
  49. var fileList = this.state.fileList;
  50. var _props = this.props,
  51. app = _props.app,
  52. action = _props.action,
  53. commentId = _props.commentId,
  54. replyId = _props.replyId,
  55. replyPage = _props.replyPage;
  56. var value = text;
  57. app.onBeforeUpdateComment();
  58. if (fileList && fileList.length) {
  59. value += _constant.IMAGE_SPLIT;
  60. fileList.forEach(function (file) {
  61. value += file.thumbUrl + ",";
  62. });
  63. }
  64. if (value.substr(-1) === ",") {
  65. value = value.slice(0, -1);
  66. }
  67. if (action === "comment") {
  68. app.sUpdateComment({ commentId: commentId, content: value });
  69. } else {
  70. app.sUpdateReply({ commentId: commentId, content: value, replyId: replyId, replyPage: replyPage });
  71. }
  72. this.props.handleClose();
  73. }
  74. }, {
  75. key: "getInitValue",
  76. value: function getInitValue(props) {
  77. var content = props.content;
  78. var newContent = content.content;
  79. var images = "";
  80. if (newContent.indexOf(_constant.IMAGE_SPLIT) !== -1) {
  81. newContent = newContent.split(_constant.IMAGE_SPLIT);
  82. images = newContent.pop();
  83. newContent = newContent.join("");
  84. }
  85. var fileList = [];
  86. if (images !== "") {
  87. fileList = images.split(",");
  88. fileList = fileList.map(function (item, index) {
  89. return {
  90. thumbUrl: item,
  91. uid: index
  92. };
  93. });
  94. }
  95. var value = this.renderTextWithReply(newContent, content);
  96. return { value: value, fileList: fileList };
  97. }
  98. }, {
  99. key: "getEmojiToolIcon",
  100. value: function getEmojiToolIcon() {
  101. return _react2.default.createElement(
  102. "div",
  103. { className: "expression-btn-wrap" },
  104. _react2.default.createElement(_icon2.default, { type: "smile", className: "icon" }),
  105. _react2.default.createElement(
  106. "span",
  107. { className: "text" },
  108. _reactIntlUniversal2.default.get("bilingually.emoji")
  109. )
  110. );
  111. }
  112. }, {
  113. key: "getImageToolIcon",
  114. value: function getImageToolIcon() {
  115. return _react2.default.createElement(
  116. "div",
  117. { className: "picture-btn-wrap" },
  118. _react2.default.createElement(_icon2.default, { type: "picture", className: "icon" }),
  119. _react2.default.createElement(
  120. "span",
  121. { className: "text" },
  122. _reactIntlUniversal2.default.get("bilingually.pic")
  123. )
  124. );
  125. }
  126. }, {
  127. key: "renderTextWithReply",
  128. value: function renderTextWithReply(text, content) {
  129. var newText = text;
  130. // const { reply } = content;
  131. // if (reply) {
  132. // newText = `${newText} //@${reply.user_name} ${reply.content}`;
  133. // if (reply.reply) {
  134. // return this.renderTextWithReply(newText, reply);
  135. // }
  136. // }
  137. return newText;
  138. }
  139. }, {
  140. key: "render",
  141. value: function render() {
  142. var _this2 = this;
  143. return _react2.default.createElement(
  144. _modal2.default,
  145. {
  146. visible: true,
  147. footer: null,
  148. wrapClassName: "editCommetModal",
  149. onCancel: this.props.handleClose
  150. },
  151. _react2.default.createElement(
  152. "div",
  153. { className: "title" },
  154. _reactIntlUniversal2.default.get("bilingually.imgtxt.edit_imgtxt")
  155. ),
  156. _react2.default.createElement(_CommentInput2.default, {
  157. content: _react2.default.createElement(_Editor2.default, {
  158. maxUpload: 9,
  159. autoFocus: true
  160. // {...this.props.editorProps}
  161. , action: this.props.action,
  162. replyId: this.props.replyId,
  163. commentId: this.props.commentId,
  164. userId: this.props.content.user_id,
  165. fileList: this.state.fileList,
  166. value: this.state.value,
  167. onChange: function onChange(value) {
  168. _this2.setState({
  169. value: value
  170. });
  171. },
  172. handleChangeFileList: function handleChangeFileList(fileList) {
  173. _this2.setState({
  174. fileList: fileList
  175. });
  176. },
  177. onSubmit: this.handleSubmit,
  178. emojiToolIcon: this.getEmojiToolIcon(),
  179. imageToolIcon: this.getImageToolIcon(),
  180. emojiPopoverPlacement: "bottom",
  181. uploadPopoverPlacement: "bottom",
  182. btnSubmitText: _reactIntlUniversal2.default.get("bilingually.imgtxt.update")
  183. })
  184. })
  185. );
  186. }
  187. }]);
  188. return EditComment;
  189. }(_react2.default.Component);
  190. exports.default = (0, _Comment2.default)(EditComment);
  191. //# sourceMappingURL=EditComment.js.map