#61 fix:#6676;add:评论失败回调

Merged
AdamFu merged 2 commits from Hepper/comment:master into master 5 years ago

+ 1
- 1
lib/components/ContentItem/AvatarHoverCard.js View File

53
   _createClass(AvatarHoverCard, [{
53
   _createClass(AvatarHoverCard, [{
54
     key: "componentDidMount",
54
     key: "componentDidMount",
55
     value: function componentDidMount() {
55
     value: function componentDidMount() {
56
-      var isLogin = this.props.currentUser.user_id > 0;
56
+      var isLogin = this.props.currentUser.user_id > 0 || this.props.currentUser.id > 0;
57
       this.props.getUserInfo({
57
       this.props.getUserInfo({
58
         id: this.props.user_id,
58
         id: this.props.user_id,
59
         noCheckFollowed: !isLogin
59
         noCheckFollowed: !isLogin

+ 1
- 1
lib/components/ContentItem/AvatarHoverCard.js.map
File diff suppressed because it is too large
View File


+ 2
- 2
lib/components/ContentItem/index.js View File

225
         }
225
         }
226
       }
226
       }
227
       var IconColor = content.favor_count > 0 ? "#71C135" : "#4a90e2";
227
       var IconColor = content.favor_count > 0 ? "#71C135" : "#4a90e2";
228
-
228
+      var showDivider = content.reply_count || showEdit && app.userId === content.user_id || app.userId === content.user_id;
229
       return _react2.default.createElement(
229
       return _react2.default.createElement(
230
         "div",
230
         "div",
231
         { className: "comment-item-box" },
231
         { className: "comment-item-box" },
381
               },
381
               },
382
               _react2.default.createElement("i", { className: "comment-item-delete" })
382
               _react2.default.createElement("i", { className: "comment-item-delete" })
383
             ),
383
             ),
384
-            _react2.default.createElement("span", { className: "comment-item-divider" }),
384
+            showDivider && _react2.default.createElement("span", { className: "comment-item-divider" }),
385
             _react2.default.createElement(
385
             _react2.default.createElement(
386
               "div",
386
               "div",
387
               {
387
               {

+ 1
- 1
lib/components/ContentItem/index.js.map
File diff suppressed because it is too large
View File


+ 0
- 1
lib/components/Editor/Upload.js View File

157
 
157
 
158
       var file = info.file;
158
       var file = info.file;
159
 
159
 
160
-      console.log(file);
161
       info.onProgress({ percent: 10 });
160
       info.onProgress({ percent: 10 });
162
       var reader = new FileReader();
161
       var reader = new FileReader();
163
       reader.readAsDataURL(info.file);
162
       reader.readAsDataURL(info.file);

+ 1
- 1
lib/components/Editor/Upload.js.map
File diff suppressed because it is too large
View File


+ 30
- 26
lib/components/Editor/index.js View File

144
   _createClass(Editor, [{
144
   _createClass(Editor, [{
145
     key: "componentDidMount",
145
     key: "componentDidMount",
146
     value: function componentDidMount() {
146
     value: function componentDidMount() {
147
-      if (this.props.app.currentUser && this.props.app.currentUser.user_id > 0) {
148
-        this.props.app.sOssSts();
147
+      var _props = this.props,
148
+          app = _props.app,
149
+          onRef = _props.onRef;
150
+
151
+      if (app.currentUser && (app.currentUser.user_id > 0 || app.currentUser.id > 0)) {
152
+        app.sOssSts();
149
       }
153
       }
150
-      if ((0, _helper.isFunction)(this.props.onRef)) {
151
-        this.props.onRef(this);
154
+      if ((0, _helper.isFunction)(onRef)) {
155
+        onRef(this);
152
       }
156
       }
153
     }
157
     }
154
   }, {
158
   }, {
373
   }, {
377
   }, {
374
     key: "checkDisabledSubmit",
378
     key: "checkDisabledSubmit",
375
     value: function checkDisabledSubmit() {
379
     value: function checkDisabledSubmit() {
376
-      var _props = this.props,
377
-          btnDisabled = _props.btnDisabled,
378
-          value = _props.value,
379
-          fileList = _props.fileList;
380
+      var _props2 = this.props,
381
+          btnDisabled = _props2.btnDisabled,
382
+          value = _props2.value,
383
+          fileList = _props2.fileList;
380
 
384
 
381
       if (btnDisabled) {
385
       if (btnDisabled) {
382
         return true;
386
         return true;
400
     value: function render() {
404
     value: function render() {
401
       var _this4 = this;
405
       var _this4 = this;
402
 
406
 
403
-      var _props2 = this.props,
404
-          value = _props2.value,
405
-          rows = _props2.rows,
406
-          showEmoji = _props2.showEmoji,
407
-          showUpload = _props2.showUpload,
408
-          multiple = _props2.multiple,
409
-          emojiPopoverPlacement = _props2.emojiPopoverPlacement,
410
-          uploadPopoverPlacement = _props2.uploadPopoverPlacement,
411
-          uploadOverlayClassName = _props2.uploadOverlayClassName,
412
-          fileList = _props2.fileList,
413
-          maxUpload = _props2.maxUpload,
414
-          btnLoading = _props2.btnLoading,
415
-          button = _props2.button,
416
-          emojiToolIcon = _props2.emojiToolIcon,
417
-          imageToolIcon = _props2.imageToolIcon,
418
-          maxLength = _props2.maxLength,
419
-          autoFocus = _props2.autoFocus,
420
-          app = _props2.app;
407
+      var _props3 = this.props,
408
+          value = _props3.value,
409
+          rows = _props3.rows,
410
+          showEmoji = _props3.showEmoji,
411
+          showUpload = _props3.showUpload,
412
+          multiple = _props3.multiple,
413
+          emojiPopoverPlacement = _props3.emojiPopoverPlacement,
414
+          uploadPopoverPlacement = _props3.uploadPopoverPlacement,
415
+          uploadOverlayClassName = _props3.uploadOverlayClassName,
416
+          fileList = _props3.fileList,
417
+          maxUpload = _props3.maxUpload,
418
+          btnLoading = _props3.btnLoading,
419
+          button = _props3.button,
420
+          emojiToolIcon = _props3.emojiToolIcon,
421
+          imageToolIcon = _props3.imageToolIcon,
422
+          maxLength = _props3.maxLength,
423
+          autoFocus = _props3.autoFocus,
424
+          app = _props3.app;
421
 
425
 
422
       var placeholder = this.props.placeholder || _reactIntlUniversal2.default.get("editor.placeholder");
426
       var placeholder = this.props.placeholder || _reactIntlUniversal2.default.get("editor.placeholder");
423
       var btnSubmitText = this.props.btnSubmitText || _reactIntlUniversal2.default.get("editor.SubmitBtn");
427
       var btnSubmitText = this.props.btnSubmitText || _reactIntlUniversal2.default.get("editor.SubmitBtn");

+ 1
- 1
lib/components/Editor/index.js.map
File diff suppressed because it is too large
View File


+ 3
- 3
lib/version.json View File

1
 {
1
 {
2
     "name":       "comment",
2
     "name":       "comment",
3
-    "buildDate":  1565080180929,
3
+    "buildDate":  1565244799639,
4
     "version":    "1.0.4",
4
     "version":    "1.0.4",
5
-    "numCommits": 181,
6
-    "hash":       "d2c0f01",
5
+    "numCommits": 182,
6
+    "hash":       "59ff040",
7
     "dirty":      false
7
     "dirty":      false
8
 }
8
 }

+ 12
- 4
src/App.js View File

310
         this.setState({ list, total: total + 1 });
310
         this.setState({ list, total: total + 1 });
311
         this.props.onCountChange(total + 1);
311
         this.props.onCountChange(total + 1);
312
       })
312
       })
313
-      .catch(this.errorHandler)
313
+      .catch(error => {
314
+        this.props.onCommentFail(error.response.status);
315
+        this.errorHandler(error);
316
+      })
314
       .finally(() => {
317
       .finally(() => {
315
         this.handleChangeLoading("sCreateComment", false);
318
         this.handleChangeLoading("sCreateComment", false);
316
       });
319
       });
407
         });
410
         });
408
         this.setState({ list });
411
         this.setState({ list });
409
       })
412
       })
410
-      .catch(this.errorHandler)
413
+      .catch(error => {
414
+        this.props.onCommentFail(error.response.status);
415
+        this.errorHandler(error);
416
+      })
411
       .finally(() => {
417
       .finally(() => {
412
         this.handleChangeLoading("sCreateReply", false);
418
         this.handleChangeLoading("sCreateReply", false);
413
       });
419
       });
640
   onDelete: PropTypes.func,
646
   onDelete: PropTypes.func,
641
   onUpdateComment: PropTypes.func,
647
   onUpdateComment: PropTypes.func,
642
   locales: PropTypes.string, //  传入的语言环境, en-US/zh-CN
648
   locales: PropTypes.string, //  传入的语言环境, en-US/zh-CN
643
-  onCountChange: PropTypes.func // 评论数量变更时的回调
649
+  onCountChange: PropTypes.func, // 评论数量变更时的回调
650
+  onCommentFail: PropTypes.func // 评论失败时的回调
644
 };
651
 };
645
 
652
 
646
 App.defaultProps = {
653
 App.defaultProps = {
665
   onDelete: () => {},
672
   onDelete: () => {},
666
   onUpdateComment: () => {},
673
   onUpdateComment: () => {},
667
   onBeforeUpdateComment: () => {},
674
   onBeforeUpdateComment: () => {},
668
-  onCountChange: () => {}
675
+  onCountChange: () => {},
676
+  onCommentFail: () => {}
669
 };
677
 };
670
 
678
 
671
 export { Editor, RenderText };
679
 export { Editor, RenderText };

+ 2
- 1
src/components/ContentItem/AvatarHoverCard.js View File

12
   }
12
   }
13
 
13
 
14
   componentDidMount() {
14
   componentDidMount() {
15
-    const isLogin = this.props.currentUser.user_id > 0;
15
+    const isLogin =
16
+      this.props.currentUser.user_id > 0 || this.props.currentUser.id > 0;
16
     this.props.getUserInfo({
17
     this.props.getUserInfo({
17
       id: this.props.user_id,
18
       id: this.props.user_id,
18
       noCheckFollowed: !isLogin
19
       noCheckFollowed: !isLogin

+ 5
- 2
src/components/ContentItem/index.js View File

130
       }
130
       }
131
     }
131
     }
132
     const IconColor = content.favor_count > 0 ? "#71C135" : "#4a90e2";
132
     const IconColor = content.favor_count > 0 ? "#71C135" : "#4a90e2";
133
-
133
+    const showDivider =
134
+      content.reply_count ||
135
+      (showEdit && app.userId === content.user_id) ||
136
+      app.userId === content.user_id;
134
     return (
137
     return (
135
       <div className="comment-item-box">
138
       <div className="comment-item-box">
136
         <div className="comment-item-left">
139
         <div className="comment-item-left">
296
                 <i className="comment-item-delete" />
299
                 <i className="comment-item-delete" />
297
               </Popconfirm>
300
               </Popconfirm>
298
             )}
301
             )}
299
-            <span className="comment-item-divider" />
302
+            {showDivider && <span className="comment-item-divider" />}
300
             <div
303
             <div
301
               className="comment-item-bottom-right"
304
               className="comment-item-bottom-right"
302
               onClick={() => {
305
               onClick={() => {

+ 0
- 1
src/components/Editor/Upload.js View File

88
 
88
 
89
   customRequest(info) {
89
   customRequest(info) {
90
     const { file } = info;
90
     const { file } = info;
91
-    console.log(file);
92
     info.onProgress({ percent: 10 });
91
     info.onProgress({ percent: 10 });
93
     let reader = new FileReader();
92
     let reader = new FileReader();
94
     reader.readAsDataURL(info.file);
93
     reader.readAsDataURL(info.file);

+ 8
- 4
src/components/Editor/index.js View File

72
   }
72
   }
73
 
73
 
74
   componentDidMount() {
74
   componentDidMount() {
75
-    if (this.props.app.currentUser && this.props.app.currentUser.user_id > 0) {
76
-      this.props.app.sOssSts();
75
+    const { app, onRef } = this.props;
76
+    if (
77
+      app.currentUser &&
78
+      (app.currentUser.user_id > 0 || app.currentUser.id > 0)
79
+    ) {
80
+      app.sOssSts();
77
     }
81
     }
78
-    if (isFunction(this.props.onRef)) {
79
-      this.props.onRef(this);
82
+    if (isFunction(onRef)) {
83
+      onRef(this);
80
     }
84
     }
81
   }
85
   }
82
 
86
 

+ 3
- 0
src/index.js View File

147
     onDelete: (type, data) => {
147
     onDelete: (type, data) => {
148
       console.log(type, data);
148
       console.log(type, data);
149
     },
149
     },
150
+    onCommentFail: data => {
151
+      console.log("onCommentFail", data);
152
+    },
150
     onUpdateComment: (type, data) => {
153
     onUpdateComment: (type, data) => {
151
       console.log("onUpdateComment", type);
154
       console.log("onUpdateComment", type);
152
     },
155
     },