Skip to content

Commit

Permalink
Merge pull request #818 from LessWrong2/fixMarkdownEditing
Browse files Browse the repository at this point in the history
Fix markdownediting for comments created with rich-text-editor
  • Loading branch information
Raemon committed Aug 21, 2018
2 parents 60a18cd + f87d6a7 commit 8e15fe2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
14 changes: 14 additions & 0 deletions packages/lesswrong/components/editor/CommentEditor.jsx
Expand Up @@ -18,8 +18,18 @@ class CommentEditor extends Component {
}

async componentWillMount() {
const { currentUser } = this.props
const {default: Editor} = await import('../async/AsyncCommentEditor.jsx');
this.setState({editor: Editor});
const removeUnusedFields = (data) => {
let { content, body, ...newData } = data
if (Users.useMarkdownCommentEditor(currentUser)) {
return {...newData, body}
} else {
return {...newData, content}
}
}
this.context.addToSubmitForm(removeUnusedFields);
}

render() {
Expand All @@ -40,4 +50,8 @@ class CommentEditor extends Component {
}
}

CommentEditor.contextTypes = {
addToSubmitForm: PropTypes.func,
};

registerComponent('CommentEditor', CommentEditor, withCurrentUser, withStyles(styles));
15 changes: 15 additions & 0 deletions packages/lesswrong/components/editor/EditorFormComponent.jsx
Expand Up @@ -21,8 +21,19 @@ class EditorFormComponent extends Component {
}

async componentWillMount() {
const { currentUser } = this.props
const {default: Editor} = await import('../async/AsyncEditorFormComponent.jsx');
this.setState({editor: Editor});

const removeUnusedFields = (data) => {
let { content, body, ...newData } = data
if (Users.useMarkdownPostEditor(currentUser)) {
return {...newData, body}
} else {
return {...newData, content}
}
}
this.context.addToSubmitForm(removeUnusedFields);
}

render() {
Expand All @@ -44,4 +55,8 @@ class EditorFormComponent extends Component {
}
}

EditorFormComponent.contextTypes = {
addToSubmitForm: PropTypes.func,
};

registerComponent('EditorFormComponent', EditorFormComponent, withCurrentUser, withStyles(styles));
7 changes: 4 additions & 3 deletions packages/lesswrong/lib/collections/comments/custom_fields.js
Expand Up @@ -59,11 +59,12 @@ Comments.addField([
order: 25,
form: {
hintText:"Plain Markdown Editor",
name:"body",
rows:4,
multiLine:true,
fullWidth:true,
underlineShow:false
disableUnderline:true,
enableMarkDownEditor: true,
minHeight: 400,
name: "body"
},
}
},
Expand Down

0 comments on commit 8e15fe2

Please sign in to comment.