Browse Source

detect layoutType on CommentForm

Yuki Takei 7 years ago
parent
commit
4d2844798f
1 changed files with 24 additions and 6 deletions
  1. 24 6
      src/client/js/components/PageComment/CommentForm.jsx

+ 24 - 6
src/client/js/components/PageComment/CommentForm.jsx

@@ -33,6 +33,7 @@ export default class CommentForm extends React.Component {
     const isUploadableFile = config.upload.file;
 
     this.state = {
+      isLayoutTypeGrowi: false,
       isFormShown: false,
       comment: '',
       isMarkdown: true,
@@ -60,6 +61,19 @@ export default class CommentForm extends React.Component {
     this.showCommentFormBtnClickHandler = this.showCommentFormBtnClickHandler.bind(this);
   }
 
+  componentWillMount() {
+    this.init();
+  }
+
+  init() {
+    if (!this.props.pageId) {
+      return;
+    }
+
+    const layoutType = this.props.crowi.getConfig()['layoutType'];
+    this.setState({isLayoutTypeGrowi: 'crowi-plus' === layoutType || 'growi' === layoutType});
+  }
+
   updateState(value) {
     this.setState({comment: value});
   }
@@ -227,6 +241,8 @@ export default class CommentForm extends React.Component {
     const commentPreview = this.state.isMarkdown ? this.getCommentHtml(): ReactUtils.nl2br(comment);
     const emojiStrategy = this.props.crowi.getEmojiStrategy();
 
+    const isLayoutTypeGrowi = this.state.isLayoutTypeGrowi;
+
     const errorMessage = <span className="text-danger text-right mr-2">{this.state.errorMessage}</span>;
     const submitButton = (
       <Button type="submit" bsStyle="primary" className="fcbtn btn btn-sm btn-primary btn-outline btn-rounded btn-1b">
@@ -240,11 +256,13 @@ export default class CommentForm extends React.Component {
         <form className="form page-comment-form" id="page-comment-form" onSubmit={this.postComment}>
           { username &&
             <div className="comment-form">
-              <div className="comment-form-user">
-                <a href={creatorsPage}>
-                  <UserPicture user={user} />
-                </a>
-              </div>
+              { isLayoutTypeGrowi &&
+                <div className="comment-form-user">
+                  <a href={creatorsPage}>
+                    <UserPicture user={user} />
+                  </a>
+                </div>
+              }
               <div className="comment-form-main">
                 {/* Add Comment Button */}
                 { !this.state.isFormShown &&
@@ -263,7 +281,7 @@ export default class CommentForm extends React.Component {
                           editorOptions={this.props.editorOptions}
                           lineNumbers={false}
                           isMobile={this.props.crowi.isMobile}
-                          isUploadable={this.state.isUploadable}
+                          isUploadable={this.state.isUploadable && this.state.isLayoutTypeGrowi}  // enable only when GROWI layout
                           isUploadableFile={this.state.isUploadableFile}
                           emojiStrategy={emojiStrategy}
                           onChange={this.updateState}