Explorar o código

FB commentEditor

itizawa %!s(int64=6) %!d(string=hai) anos
pai
achega
f39d32621c
Modificáronse 1 ficheiros con 35 adicións e 24 borrados
  1. 35 24
      src/client/js/components/PageComment/CommentEditor.jsx

+ 35 - 24
src/client/js/components/PageComment/CommentEditor.jsx

@@ -88,6 +88,19 @@ class CommentEditor extends React.Component {
     this.props.commentButtonClickedHandler(targetId);
     this.props.commentButtonClickedHandler(targetId);
   }
   }
 
 
+  initializeEditor() {
+    this.setState({
+      comment: '',
+      isMarkdown: true,
+      html: '',
+      key: 1,
+      errorMessage: undefined,
+    });
+    // reset value
+    this.editor.setValue('');
+    this.toggleEditor();
+  }
+
   /**
   /**
    * Post comment with CommentContainer and update state
    * Post comment with CommentContainer and update state
    */
    */
@@ -97,37 +110,35 @@ class CommentEditor extends React.Component {
     }
     }
 
 
     if (this.props.currentCommentId != null) {
     if (this.props.currentCommentId != null) {
-      await this.props.commentContainer.putComment(
-        this.state.comment,
-        this.state.isMarkdown,
-        this.props.currentCommentId,
-      ).catch((err) => {
+      try {
+        await this.props.commentContainer.putComment(
+          this.state.comment,
+          this.state.isMarkdown,
+          this.props.currentCommentId,
+        );
+        this.initializeEditor();
+      }
+      catch (err) {
         const errorMessage = err.message || 'An unknown error occured when puting comment';
         const errorMessage = err.message || 'An unknown error occured when puting comment';
         this.setState({ errorMessage });
         this.setState({ errorMessage });
-      });
+      }
     }
     }
     else {
     else {
-      await this.props.commentContainer.postComment(
-        this.state.comment,
-        this.state.isMarkdown,
-        this.props.replyTo,
-        this.props.commentContainer.state.isSlackEnabled,
-        this.props.commentContainer.state.slackChannels,
-      ).catch((err) => {
+      try {
+        await this.props.commentContainer.postComment(
+          this.state.comment,
+          this.state.isMarkdown,
+          this.props.replyTo,
+          this.props.commentContainer.state.isSlackEnabled,
+          this.props.commentContainer.state.slackChannels,
+        );
+        this.initializeEditor();
+      }
+      catch (err) {
         const errorMessage = err.message || 'An unknown error occured when posting comment';
         const errorMessage = err.message || 'An unknown error occured when posting comment';
         this.setState({ errorMessage });
         this.setState({ errorMessage });
-      });
+      }
     }
     }
-    this.setState({
-      comment: '',
-      isMarkdown: true,
-      html: '',
-      key: 1,
-      errorMessage: undefined,
-    });
-    // reset value
-    this.editor.setValue('');
-    this.toggleEditor();
   }
   }
 
 
   uploadHandler(file) {
   uploadHandler(file) {