Просмотр исходного кода

(WIP) comment-write with editor-component

yusuketk 7 лет назад
Родитель
Сommit
f7ff3ad654
2 измененных файлов с 36 добавлено и 19 удалено
  1. 15 14
      resource/js/app.js
  2. 21 5
      resource/js/components/PageComment/CommentForm.js

+ 15 - 14
resource/js/app.js

@@ -130,20 +130,6 @@ Object.keys(componentMappings).forEach((key) => {
   }
   }
 });
 });
 
 
-// render comment form
-const writeCommentElem = document.getElementById('page-comment-write');
-if (writeCommentElem) {
-  const pageCommentsElem = componentInstances['page-comments-list'];
-  const postCompleteHandler = (comment) => {
-    if (pageCommentsElem != null) {
-      pageCommentsElem.retrieveData();
-    }
-  };
-  ReactDOM.render(
-    <CommentForm crowi={crowi} pageId={pageId} revisionId={pageRevisionId} onPostComplete={postCompleteHandler} crowiRenderer={crowiRenderer}/>,
-    writeCommentElem);
-}
-
 /*
 /*
  * PageEditor
  * PageEditor
  */
  */
@@ -174,6 +160,21 @@ if (pageEditorElem) {
   // set refs for pageEditor
   // set refs for pageEditor
   crowi.setPageEditor(pageEditor);
   crowi.setPageEditor(pageEditor);
 }
 }
+
+// render comment form
+const writeCommentElem = document.getElementById('page-comment-write');
+if (writeCommentElem) {
+  const pageCommentsElem = componentInstances['page-comments-list'];
+  const postCompleteHandler = (comment) => {
+    if (pageCommentsElem != null) {
+      pageCommentsElem.retrieveData();
+    }
+  };
+  ReactDOM.render(
+    <CommentForm crowi={crowi} pageId={pageId} revisionId={pageRevisionId} onPostComplete={postCompleteHandler} crowiRenderer={crowiRenderer} editorOptions={editorOptions}/>,
+    writeCommentElem);
+}
+
 // render OptionsSelector
 // render OptionsSelector
 const pageEditorOptionsSelectorElem = document.getElementById('page-editor-options-selector');
 const pageEditorOptionsSelectorElem = document.getElementById('page-editor-options-selector');
 if (pageEditorOptionsSelectorElem) {
 if (pageEditorOptionsSelectorElem) {

+ 21 - 5
resource/js/components/PageComment/CommentForm.js

@@ -2,6 +2,7 @@ import React from 'react';
 import PropTypes from 'prop-types';
 import PropTypes from 'prop-types';
 import ReactUtils from '../ReactUtils';
 import ReactUtils from '../ReactUtils';
 
 
+import Editor from '../PageEditor/Editor';
 import CommentPreview from '../PageComment/CommentPreview';
 import CommentPreview from '../PageComment/CommentPreview';
 
 
 import Button from 'react-bootstrap/es/Button';
 import Button from 'react-bootstrap/es/Button';
@@ -28,6 +29,7 @@ export default class CommentForm extends React.Component {
       isMarkdown: true,
       isMarkdown: true,
       html: '',
       html: '',
       key: 1,
       key: 1,
+      editorOptions: this.props.editorOptions,
     };
     };
 
 
     this.updateState = this.updateState.bind(this);
     this.updateState = this.updateState.bind(this);
@@ -38,11 +40,11 @@ export default class CommentForm extends React.Component {
 
 
   updateState(event) {
   updateState(event) {
     const target = event.target;
     const target = event.target;
-    const value = target.type === 'checkbox' ? target.checked : target.value;
-    const name = target.name;
+    // const value = target.type === 'checkbox' ? target.checked : target.value;
+    // const name = target.name;
 
 
     this.setState({
     this.setState({
-      [name]: value
+      // [name]: value
     });
     });
   }
   }
 
 
@@ -129,6 +131,7 @@ export default class CommentForm extends React.Component {
     const creatorsPage = `/user/${username}`;
     const creatorsPage = `/user/${username}`;
     const comment = this.state.comment;
     const comment = this.state.comment;
     const commentPreview = this.state.isMarkdown ? this.getCommentHtml(): ReactUtils.nl2br(comment);
     const commentPreview = this.state.isMarkdown ? this.getCommentHtml(): ReactUtils.nl2br(comment);
+    const emojiStrategy = this.props.crowi.getEmojiStrategy();
 
 
     return (
     return (
       <div>
       <div>
@@ -144,8 +147,21 @@ export default class CommentForm extends React.Component {
                 <div className="comment-write">
                 <div className="comment-write">
                   <Tabs activeKey={this.state.key} id="comment-form-tabs" onSelect={this.handleSelect} animation={false}>
                   <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>
+                      {/* <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> */}
+                       <Editor ref="editor" type="text"
+                       value={this.state.comment}
+                        editorOptions={this.state.editorOptions}
+                        isMobile={this.props.crowi.isMobile}
+                        // isUploadable={this.state.isUploadable}
+                        // isUploadableFile={this.state.isUploadableFile}
+                        emojiStrategy={emojiStrategy}
+                        // onScroll={this.onEditorScroll}
+                        // onScrollCursorIntoView={this.onEditorScrollCursorIntoView}
+                        onChange={this.updateState}
+                        // onSave={this.onSave}
+                        // onUpload={this.onUpload}
+                      />
                     </Tab>
                     </Tab>
                     { this.state.isMarkdown == true &&
                     { this.state.isMarkdown == true &&
                     <Tab eventKey={2} title="Preview">
                     <Tab eventKey={2} title="Preview">