Explorar o código

comment-form tab reset active-tab when commented

yusuketk %!s(int64=7) %!d(string=hai) anos
pai
achega
cdb3460475
Modificáronse 1 ficheiros con 10 adicións e 7 borrados
  1. 10 7
      resource/js/components/PageComment/CommentForm.js

+ 10 - 7
resource/js/components/PageComment/CommentForm.js

@@ -27,12 +27,13 @@ export default class CommentForm extends React.Component {
       comment: '',
       comment: '',
       isMarkdown: true,
       isMarkdown: true,
       html: '',
       html: '',
-    };
+      key: 1,
+       };
 
 
     this.updateState = this.updateState.bind(this);
     this.updateState = this.updateState.bind(this);
     this.postComment = this.postComment.bind(this);
     this.postComment = this.postComment.bind(this);
     this.renderHtml = this.renderHtml.bind(this);
     this.renderHtml = this.renderHtml.bind(this);
-    this.getCommentHtml = this.getCommentHtml.bind(this);
+    this.handleSelect = this.handleSelect.bind(this);
   }
   }
 
 
   updateState(event) {
   updateState(event) {
@@ -45,13 +46,15 @@ export default class CommentForm extends React.Component {
     });
     });
   }
   }
 
 
-  getCommentHtml(){
+  handleSelect(key){
+    this.setState({ key });
     if(this.state.isMarkdown){
     if(this.state.isMarkdown){
       this.renderHtml(this.state.comment)
       this.renderHtml(this.state.comment)
     } else {
     } else {
      this.setState({ html: this.state.comment})
      this.setState({ html: this.state.comment})
     }
     }
   }
   }
+
   /**
   /**
    * Load data of comments and rerender <PageComments />
    * Load data of comments and rerender <PageComments />
    */
    */
@@ -72,7 +75,9 @@ export default class CommentForm extends React.Component {
         }
         }
         this.setState({
         this.setState({
           comment: '',
           comment: '',
-          isMarkdown: false,
+          isMarkdown: true,
+          html: '',
+          key: 1,
         });
         });
       });
       });
   }
   }
@@ -114,9 +119,7 @@ export default class CommentForm extends React.Component {
 
 
 
 
 render() {
 render() {
-  console.log(this.state.html)
   //{% if not user %}disabled{% endif %}をtextareaとbuttonに追加
   //{% if not user %}disabled{% endif %}をtextareaとbuttonに追加
-  // denounce/throttle
   return (
   return (
     <div>
     <div>
       <form className="form page-comment-form" id="page-comment-form" onSubmit={this.postComment}>
       <form className="form page-comment-form" id="page-comment-form" onSubmit={this.postComment}>
@@ -125,7 +128,7 @@ render() {
           </div>
           </div>
           <div className="comment-form-main">
           <div className="comment-form-main">
             <div className="comment-write">
             <div className="comment-write">
- 	        		<Tabs defaultActiveKey={1} id="comment-form-tabs" onSelect={this.getCommentHtml}>
+ 	        		<Tabs activeKey={this.state.key} id="comment-form-tabs" onSelect={this.handleSelect} animation={false}>
                 <Tab eventKey={1} title="Write">
                 <Tab eventKey={1} title="Write">
                   <textarea className="comment-form-comment form-control" id="comment-form-comment" name="comment" required placeholder="Write comments here..." value={this.state.comment} onChange={this.updateState} >
                   <textarea className="comment-form-comment form-control" id="comment-form-comment" name="comment" required placeholder="Write comments here..." value={this.state.comment} onChange={this.updateState} >
                   </textarea>
                   </textarea>