Przeglądaj źródła

add: 删除评论回调增加参数

zhengyingya 5 lat temu
rodzic
commit
388cc92ed3

+ 11
- 4
lib/App.js Wyświetl plik

@@ -356,7 +356,7 @@ var App = function (_Component) {
356 356
         if (_this5.props.showAlertComment) {
357 357
           _message3.default.success(_reactIntlUniversal2.default.get("message.success"));
358 358
         }
359
-        if ((0, _helper.isFunction)(cb)) cb();
359
+        if ((0, _helper.isFunction)(cb)) cb(response.data);
360 360
         // 将数据写入到 list 中
361 361
         // 临时插入
362 362
         // 等到获取数据之后,删除临时数据
@@ -397,8 +397,11 @@ var App = function (_Component) {
397 397
         var res = list.filter(function (item) {
398 398
           return item.id !== commentId;
399 399
         });
400
+        var deletedItem = list.find(function (item) {
401
+          return item.id === commentId;
402
+        });
400 403
         _this6.setState({ list: res, total: total - 1 });
401
-        _this6.props.onDelete(_constant.COMMENT_TYPE.COMMENT);
404
+        _this6.props.onDelete(_constant.COMMENT_TYPE.COMMENT, deletedItem);
402 405
         _this6.props.onCountChange(total - 1);
403 406
       }).catch(this.errorHandler).finally(function () {
404 407
         _this6.handleChangeLoading("sDeleteComment", false);
@@ -428,7 +431,7 @@ var App = function (_Component) {
428 431
         if (_this7.props.showAlertReply) {
429 432
           _message3.default.success(_reactIntlUniversal2.default.get("message.replySuccess"));
430 433
         }
431
-        if ((0, _helper.isFunction)(cb)) cb();
434
+        if ((0, _helper.isFunction)(cb)) cb(response.data);
432 435
         // 将数据写入到 list 中
433 436
         // 临时插入
434 437
         // 等到获取数据之后,删除临时数据
@@ -466,18 +469,22 @@ var App = function (_Component) {
466 469
         method: "delete",
467 470
         withCredentials: true
468 471
       }).then(function () {
472
+        var deletedItem = null;
469 473
         var list = _this8.state.list.map(function (item) {
470 474
           if (item.id === commentId) {
471 475
             var replies = item.replies.filter(function (item) {
472 476
               return item.id !== replyId;
473 477
             });
478
+            deletedItem = item.replies.find(function (item) {
479
+              return item.id === replyId;
480
+            });
474 481
             item.replies = replies;
475 482
             item.reply_count -= 1;
476 483
           }
477 484
           return item;
478 485
         });
479 486
         _this8.setState({ list: list });
480
-        _this8.props.onDelete(_constant.COMMENT_TYPE.REPLY);
487
+        _this8.props.onDelete(_constant.COMMENT_TYPE.REPLY, deletedItem);
481 488
       }).catch(this.errorHandler).finally(function () {
482 489
         _this8.handleChangeLoading("sDeleteReply", false);
483 490
       });

+ 1
- 1
lib/App.js.map
Plik diff jest za duży
Wyświetl plik


+ 4
- 4
lib/components/CommentInput/index.js Wyświetl plik

@@ -83,8 +83,8 @@ var CommentInput = function (_Component) {
83 83
           comment_id: commentId,
84 84
           content: value,
85 85
           business_user_id: userId
86
-        }, function () {
87
-          return callback && callback();
86
+        }, function (data) {
87
+          return callback && callback(data);
88 88
         });
89 89
       } else if (action === "replyToReply") {
90 90
         this.props.app.sCreateReply({
@@ -92,8 +92,8 @@ var CommentInput = function (_Component) {
92 92
           content: value,
93 93
           reply_id: replyId,
94 94
           business_user_id: userId
95
-        }, function () {
96
-          return callback && callback();
95
+        }, function (data) {
96
+          return callback && callback(data);
97 97
         });
98 98
       }
99 99
     }

+ 1
- 1
lib/components/CommentInput/index.js.map
Plik diff jest za duży
Wyświetl plik


+ 14
- 10
lib/components/ContentItem/index.js Wyświetl plik

@@ -118,6 +118,7 @@ var CommentItem = function (_Component) {
118 118
     _this.showPreviewer = _this.showPreviewer.bind(_this);
119 119
     _this.hidePreviewer = _this.hidePreviewer.bind(_this);
120 120
     _this.handleVisibleChange = _this.handleVisibleChange.bind(_this);
121
+    _this.handleUserAvaClick = _this.handleUserAvaClick.bind(_this);
121 122
     return _this;
122 123
   }
123 124
 
@@ -148,6 +149,16 @@ var CommentItem = function (_Component) {
148 149
         popoverVisible: visible
149 150
       });
150 151
     }
152
+  }, {
153
+    key: "handleUserAvaClick",
154
+    value: function handleUserAvaClick() {
155
+      var user_id = this.props.user_id;
156
+      var userAvaClick = this.props.app.userAvaClick;
157
+
158
+      if (userAvaClick) {
159
+        userAvaClick(user_id);
160
+      }
161
+    }
151 162
   }, {
152 163
     key: "renderTextWithReply",
153 164
     value: function renderTextWithReply(text, content) {
@@ -187,7 +198,6 @@ var CommentItem = function (_Component) {
187 198
           user_id = _props.user_id;
188 199
       var _props$app = this.props.app,
189 200
           locale = _props$app.locale,
190
-          userAvaClick = _props$app.userAvaClick,
191 201
           showHoverCard = _props$app.showHoverCard;
192 202
       var showInput = this.state.showInput;
193 203
 
@@ -240,18 +250,14 @@ var CommentItem = function (_Component) {
240 250
               style: {
241 251
                 backgroundImage: "url(" + (content.user_avatar || _avatar2.default) + ")"
242 252
               },
243
-              onClick: function onClick() {
244
-                return userAvaClick(user_id);
245
-              }
253
+              onClick: this.handleUserAvaClick
246 254
             })
247 255
           ) : _react2.default.createElement("div", {
248 256
             className: "comment-item-avatar",
249 257
             style: {
250 258
               backgroundImage: "url(" + (content.user_avatar || _avatar2.default) + ")"
251 259
             },
252
-            onClick: function onClick() {
253
-              userAvaClick(user_id);
254
-            }
260
+            onClick: this.handleUserAvaClick
255 261
           })
256 262
         ),
257 263
         _react2.default.createElement(
@@ -263,9 +269,7 @@ var CommentItem = function (_Component) {
263 269
             _react2.default.createElement(
264 270
               "strong",
265 271
               {
266
-                onClick: function onClick() {
267
-                  return userAvaClick(user_id);
268
-                },
272
+                onClick: this.handleUserAvaClick,
269 273
                 style: { cursor: "pointer" }
270 274
               },
271 275
               content.user_name || _reactIntlUniversal2.default.get("comment.tourist")

+ 1
- 1
lib/components/ContentItem/index.js.map
Plik diff jest za duży
Wyświetl plik


+ 5
- 0
lib/components/Editor/Upload.css Wyświetl plik

@@ -7,3 +7,8 @@
7 7
   margin-top: 8px;
8 8
   color: #666;
9 9
 }
10
+
11
+.upload-img-preview .ant-modal-close {
12
+  top: -10px;
13
+  right: -15px;
14
+}

+ 1
- 0
lib/components/Editor/Upload.js Wyświetl plik

@@ -200,6 +200,7 @@ var App = function (_React$Component) {
200 200
         _react2.default.createElement(
201 201
           _modal2.default,
202 202
           {
203
+            className: "upload-img-preview",
203 204
             visible: previewVisible,
204 205
             footer: null,
205 206
             onCancel: this.handleCancel

+ 1
- 1
lib/components/Editor/Upload.js.map
Plik diff jest za duży
Wyświetl plik


+ 4
- 4
lib/components/Editor/index.js Wyświetl plik

@@ -247,19 +247,19 @@ var Editor = function (_React$Component) {
247 247
       if (this.props.beforeSubmit) {
248 248
         Promise.resolve(this.props.beforeSubmit({ text: value, files: files })).then(function (res) {
249 249
           if (!(res === false)) {
250
-            _this2.props.onSubmit({ text: value, files: files }, function () {
250
+            _this2.props.onSubmit({ text: value, files: files }, function (res) {
251 251
               _this2.resetState();
252 252
               if (_this2.props.onCommentSuccess) {
253
-                _this2.props.onCommentSuccess();
253
+                _this2.props.onCommentSuccess(res);
254 254
               }
255 255
             });
256 256
           }
257 257
         });
258 258
       } else {
259
-        this.props.onSubmit({ text: value, files: files }, function () {
259
+        this.props.onSubmit({ text: value, files: files }, function (res) {
260 260
           _this2.resetState();
261 261
           if (_this2.props.onCommentSuccess) {
262
-            _this2.props.onCommentSuccess();
262
+            _this2.props.onCommentSuccess(res);
263 263
           }
264 264
         });
265 265
       }

+ 1
- 1
lib/components/Editor/index.js.map
Plik diff jest za duży
Wyświetl plik


+ 9
- 2
lib/index.js Wyświetl plik

@@ -111,7 +111,7 @@ if (process.env.NODE_ENV !== "production") {
111 111
     type: 1,
112 112
     businessId: "test",
113 113
     businessUserId: 4,
114
-    userId: 71299,
114
+    userId: 71748,
115 115
     currentUser: {
116 116
       user_id: 71748
117 117
     },
@@ -158,7 +158,14 @@ if (process.env.NODE_ENV !== "production") {
158 158
     onCountChange: function onCountChange(c) {
159 159
       console.log(c);
160 160
     },
161
-    editorProps: {}
161
+    onDelete: function onDelete(type, data) {
162
+      console.log(type, data);
163
+    },
164
+    editorProps: {
165
+      onCommentSuccess: function onCommentSuccess(data) {
166
+        console.log(data);
167
+      }
168
+    }
162 169
   });
163 170
 }
164 171
 

+ 1
- 1
lib/index.js.map
Plik diff jest za duży
Wyświetl plik


+ 3
- 3
lib/version.json Wyświetl plik

@@ -1,8 +1,8 @@
1 1
 {
2 2
     "name":       "comment",
3
-    "buildDate":  1562073871881,
3
+    "buildDate":  1562985105668,
4 4
     "version":    "1.0.4",
5
-    "numCommits": 158,
6
-    "hash":       "1b15efb",
5
+    "numCommits": 161,
6
+    "hash":       "a7dfeba",
7 7
     "dirty":      true
8 8
 }

+ 5
- 2
src/App.js Wyświetl plik

@@ -277,8 +277,9 @@ class App extends Component {
277 277
       .then(() => {
278 278
         const { list, total } = this.state;
279 279
         const res = list.filter(item => item.id !== commentId);
280
+        const deletedItem = list.find(item => item.id === commentId);
280 281
         this.setState({ list: res, total: total - 1 });
281
-        this.props.onDelete(COMMENT_TYPE.COMMENT);
282
+        this.props.onDelete(COMMENT_TYPE.COMMENT, deletedItem);
282 283
         this.props.onCountChange(total - 1);
283 284
       })
284 285
       .catch(this.errorHandler)
@@ -341,16 +342,18 @@ class App extends Component {
341 342
       withCredentials: true
342 343
     })
343 344
       .then(() => {
345
+        let deletedItem = null;
344 346
         const list = this.state.list.map(item => {
345 347
           if (item.id === commentId) {
346 348
             const replies = item.replies.filter(item => item.id !== replyId);
349
+            deletedItem = item.replies.find(item => item.id === replyId);
347 350
             item.replies = replies;
348 351
             item.reply_count -= 1;
349 352
           }
350 353
           return item;
351 354
         });
352 355
         this.setState({ list });
353
-        this.props.onDelete(COMMENT_TYPE.REPLY);
356
+        this.props.onDelete(COMMENT_TYPE.REPLY, deletedItem);
354 357
       })
355 358
       .catch(this.errorHandler)
356 359
       .finally(() => {

+ 8
- 9
src/components/CommentInput/index.js Wyświetl plik

@@ -36,15 +36,14 @@ class CommentInput extends Component {
36 36
         cb
37 37
       );
38 38
     } else if (action === "reply") {
39
-      console.log("[[[", callback);
40
-      // this.props.app.sCreateReply(
41
-      //   {
42
-      //     comment_id: commentId,
43
-      //     content: value,
44
-      //     business_user_id: userId
45
-      //   },
46
-      //   (data) => callback && callback(data)
47
-      // );
39
+      this.props.app.sCreateReply(
40
+        {
41
+          comment_id: commentId,
42
+          content: value,
43
+          business_user_id: userId
44
+        },
45
+        data => callback && callback(data)
46
+      );
48 47
     } else if (action === "replyToReply") {
49 48
       this.props.app.sCreateReply(
50 49
         {

+ 3
- 2
src/components/ContentItem/index.js Wyświetl plik

@@ -36,6 +36,7 @@ class CommentItem extends Component {
36 36
     this.showPreviewer = this.showPreviewer.bind(this);
37 37
     this.hidePreviewer = this.hidePreviewer.bind(this);
38 38
     this.handleVisibleChange = this.handleVisibleChange.bind(this);
39
+    this.handleUserAvaClick = this.handleUserAvaClick.bind(this);
39 40
   }
40 41
 
41 42
   showPreviewer(index) {
@@ -61,13 +62,13 @@ class CommentItem extends Component {
61 62
     });
62 63
   }
63 64
 
64
-  handleUserAvaClick = () => {
65
+  handleUserAvaClick() {
65 66
     const { user_id } = this.props;
66 67
     const { userAvaClick } = this.props.app;
67 68
     if (userAvaClick) {
68 69
       userAvaClick(user_id);
69 70
     }
70
-  };
71
+  }
71 72
 
72 73
   renderTextWithReply(text, content) {
73 74
     let newText = text;

+ 4
- 1
src/index.js Wyświetl plik

@@ -76,7 +76,7 @@ if (process.env.NODE_ENV !== "production") {
76 76
     type: 1,
77 77
     businessId: "test",
78 78
     businessUserId: 4,
79
-    userId: 71299,
79
+    userId: 71748,
80 80
     currentUser: {
81 81
       user_id: 71748
82 82
     },
@@ -123,6 +123,9 @@ if (process.env.NODE_ENV !== "production") {
123 123
     onCountChange: c => {
124 124
       console.log(c);
125 125
     },
126
+    onDelete: (type, data) => {
127
+      console.log(type, data);
128
+    },
126 129
     editorProps: {
127 130
       onCommentSuccess: data => {
128 131
         console.log(data);