Browse Source

retrieve data again when posted successfully

Yuki Takei 6 years ago
parent
commit
6c063beccb
1 changed files with 3 additions and 10 deletions
  1. 3 10
      src/client/js/components/PageComment/CommentContainer.jsx

+ 3 - 10
src/client/js/components/PageComment/CommentContainer.jsx

@@ -19,7 +19,7 @@ export default class CommentContainer extends Container {
       comments: [],
     };
 
-    this.add = this.add.bind(this);
+    this.retrieveComments = this.retrieveComments.bind(this);
   }
 
   init() {
@@ -28,13 +28,6 @@ export default class CommentContainer extends Container {
     }
   }
 
-  add(comment) {
-    const comments = this.state.comments;
-
-    comments.push(comment);
-    this.setState({ comments });
-  }
-
   findAndSplice(comment) {
     const comments = this.state.comments;
 
@@ -52,7 +45,7 @@ export default class CommentContainer extends Container {
    */
   retrieveComments() {
     // get data (desc order array)
-    this.crowi.apiGet('/comments.get', { page_id: this.pageId })
+    return this.crowi.apiGet('/comments.get', { page_id: this.pageId })
       .then((res) => {
         if (res.ok) {
           this.setState({ comments: res.comments });
@@ -80,7 +73,7 @@ export default class CommentContainer extends Container {
     })
       .then((res) => {
         if (res.ok) {
-          this.add(res.comment);
+          return this.retrieveComments();
         }
       });
   }