Browse Source

Componentization comment control

itizawa 6 years ago
parent
commit
6c2102d67a

+ 3 - 13
src/client/js/components/PageComment/Comment.jsx

@@ -16,6 +16,7 @@ import RevisionBody from '../Page/RevisionBody';
 import UserPicture from '../User/UserPicture';
 import UserPicture from '../User/UserPicture';
 import Username from '../User/Username';
 import Username from '../User/Username';
 import CommentEditor from './CommentEditor';
 import CommentEditor from './CommentEditor';
+import CommentControl from './CommentControl';
 
 
 /**
 /**
  *
  *
@@ -233,18 +234,6 @@ class Comment extends React.Component {
     );
     );
   }
   }
 
 
-  renderCommentControl(comment) {
-    return (
-      <div className="page-comment-control">
-        <button type="button" className="btn btn-link p-2" onClick={() => { this.editBtnClickedHandler(comment._id) }}>
-          <i className="ti-pencil"></i>
-        </button>
-        <button type="button" className="btn btn-link p-2 mr-2" onClick={this.deleteBtnClickedHandler}>
-          <i className="ti-close"></i>
-        </button>
-      </div>
-    );
-  }
 
 
   render() {
   render() {
     const comment = this.props.comment;
     const comment = this.props.comment;
@@ -308,7 +297,8 @@ class Comment extends React.Component {
                 ) }
                 ) }
                 <span className="ml-2"><a className={revisionLavelClassName} href={revHref}>{revFirst8Letters}</a></span>
                 <span className="ml-2"><a className={revisionLavelClassName} href={revHref}>{revFirst8Letters}</a></span>
               </div>
               </div>
-              { this.checkPermissionToControlComment() && this.renderCommentControl(comment) }
+              { this.checkPermissionToControlComment()
+                  && <CommentControl comment={comment} onClickDeleteBtn={this.deleteBtnClickedHandler} onClickEditBtn={this.editBtnClickedHandler} />}
             </div>
             </div>
           </div>
           </div>
         )
         )

+ 25 - 0
src/client/js/components/PageComment/CommentControl.jsx

@@ -0,0 +1,25 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+
+
+const CommentControl = (props) => {
+  return (
+    <div className="page-comment-control">
+      <button type="button" className="btn btn-link p-2" onClick={() => { props.onClickEditBtn(props.comment._id) }}>
+        <i className="ti-pencil"></i>
+      </button>
+      <button type="button" className="btn btn-link p-2 mr-2" onClick={props.onClickDeleteBtn}>
+        <i className="ti-close"></i>
+      </button>
+    </div>
+  );
+};
+
+CommentControl.propTypes = {
+  comment: PropTypes.object.isRequired,
+
+  onClickEditBtn: PropTypes.func.isRequired,
+  onClickDeleteBtn: PropTypes.func.isRequired,
+};
+
+export default CommentControl;