itizawa 6 лет назад
Родитель
Сommit
45d40a82ae

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

@@ -104,32 +104,49 @@ class CommentEditor extends React.Component {
         this.props.commentContainer.state.isSlackEnabled,
         this.props.commentContainer.state.slackChannels,
         this.props.currentCommentId,
-      );
+      )
+        .then((res) => {
+          this.setState({
+            comment: '',
+            isMarkdown: true,
+            html: '',
+            key: 1,
+            errorMessage: undefined,
+          });
+          // reset value
+          this.editor.setValue('');
+          this.toggleEditor();
+        })
+        .catch((err) => {
+          const errorMessage = err.message || 'An unknown error occured when posting comment';
+          this.setState({ errorMessage });
+        });
     }
-
-    this.props.commentContainer.postComment(
-      this.state.comment,
-      this.state.isMarkdown,
-      this.props.replyTo,
-      this.props.commentContainer.state.isSlackEnabled,
-      this.props.commentContainer.state.slackChannels,
-    )
-      .then((res) => {
-        this.setState({
-          comment: '',
-          isMarkdown: true,
-          html: '',
-          key: 1,
-          errorMessage: undefined,
+    else {
+      this.props.commentContainer.postComment(
+        this.state.comment,
+        this.state.isMarkdown,
+        this.props.replyTo,
+        this.props.commentContainer.state.isSlackEnabled,
+        this.props.commentContainer.state.slackChannels,
+      )
+        .then((res) => {
+          this.setState({
+            comment: '',
+            isMarkdown: true,
+            html: '',
+            key: 1,
+            errorMessage: undefined,
+          });
+          // reset value
+          this.editor.setValue('');
+          this.toggleEditor();
+        })
+        .catch((err) => {
+          const errorMessage = err.message || 'An unknown error occured when posting comment';
+          this.setState({ errorMessage });
         });
-        // reset value
-        this.editor.setValue('');
-        this.toggleEditor();
-      })
-      .catch((err) => {
-        const errorMessage = err.message || 'An unknown error occured when posting comment';
-        this.setState({ errorMessage });
-      });
+    }
   }
 
   uploadHandler(file) {

+ 21 - 1
src/client/js/services/CommentContainer.js

@@ -104,7 +104,27 @@ export default class CommentContainer extends Container {
    * Load data of comments and rerender <PageComments />
    */
   putComment(comment, isMarkdown, replyTo, isSlackEnabled, slackChannels, commentId) {
-    console.log(commentId);
+    const { pageId, revisionId } = this.getPageContainer().state;
+
+    return this.appContainer.apiPost('/comments.update', {
+      commentForm: {
+        comment,
+        page_id: pageId,
+        revision_id: revisionId,
+        is_markdown: isMarkdown,
+        replyTo,
+        comment_id: commentId,
+      },
+      slackNotificationForm: {
+        isSlackEnabled,
+        slackChannels,
+      },
+    })
+      .then((res) => {
+        if (res.ok) {
+          return this.retrieveComments();
+        }
+      });
   }
 
   deleteComment(comment) {

+ 16 - 0
src/server/routes/comment.js

@@ -147,6 +147,22 @@ module.exports = function(crowi, app) {
     }
   };
 
+  /**
+   * @api {post} /comments.update Update comment dody
+   * @apiName UpdateComment
+   * @apiGroup Comment
+   *
+   */
+  api.update = function(req, res) {
+
+    if (req.body.commentForm.comment_id == null) {
+      return Promise.resolve(res.json(ApiResponse.error('\'comment_id\' is undefined')));
+    }
+
+    return console.log('Idが渡ってきています');
+  };
+
+
   /**
    * @api {post} /comments.remove Remove specified comment
    * @apiName RemoveComment

+ 1 - 0
src/server/routes/index.js

@@ -202,6 +202,7 @@ module.exports = function(crowi, app) {
   app.post('/_api/tags.update'        , accessTokenParser, loginRequired(false), tag.api.update);
   app.get('/_api/comments.get'        , accessTokenParser , loginRequired(false) , comment.api.get);
   app.post('/_api/comments.add'       , comment.api.validators.add(), accessTokenParser , loginRequired() , csrf, comment.api.add);
+  app.post('/_api/comments.update'       , comment.api.validators.add(), accessTokenParser , loginRequired() , csrf, comment.api.update);
   app.post('/_api/comments.remove'    , accessTokenParser , loginRequired() , csrf, comment.api.remove);
   app.get('/_api/bookmarks.get'       , accessTokenParser , loginRequired(false) , bookmark.api.get);
   app.post('/_api/bookmarks.add'      , accessTokenParser , loginRequired() , csrf, bookmark.api.add);