Skip to content

Commit

Permalink
Merge pull request #22 from kadirahq/fix-5
Browse files Browse the repository at this point in the history
Multiline comments support #5
  • Loading branch information
arunoda authored Oct 11, 2016
2 parents 441cc7b + 4fae6ec commit 22478ab
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"babel-preset-stage-0": "^6.5.0",
"react": "^15.3.1",
"react-dom": "^15.3.1",
"react-render-html": "^0.1.6",
"react-textarea-autosize": "^4.0.5",
"shelljs": "^0.7.4"
},
"peerDependencies": {
Expand Down
27 changes: 15 additions & 12 deletions src/manager/components/CommentForm/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import React, { Component } from 'react';
import Textarea from 'react-textarea-autosize';
import style from './style';

export default class CommentForm extends Component {
constructor(props, ...args) {
super(props, ...args);
this.state = { text: '' };
// bind functions so it can be passed later
this.onChange = this.onChange.bind(this);
this.onKeyUp = this.onKeyUp.bind(this);
this.onSubmit = this.onSubmit.bind(this);
}

onChange(e) {
const text = e.target.value;
this.setState({ text });
}

onKeyUp(e) {
if (e.key === 'Enter') {
handleKeyDown(e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
this.onSubmit();
}
}
Expand All @@ -29,24 +27,29 @@ export default class CommentForm extends Component {
return;
}

addComment(text);
const processedText = text.replace(/\r?\n/g, '<br />');
addComment(processedText);
this.setState({ text: '' });
this.forceUpdate();
}

render() {
const { text } = this.state;
return (
<div style={style.wrapper}>
<input
<Textarea
ref="commentBox"
style={style.input}
onChange={this.onChange}
onKeyUp={this.onKeyUp}
onChange={e => this.onChange(e)}
onKeyDown={e => this.handleKeyDown(e)}
placeholder="Add your comment..."
value={text}
/>
>
</Textarea>
<button
ref="submitBtn"
style={style.submitButton}
onClick={this.onSubmit}
onClick={() => this.onSubmit()}
>Submit
</button>
</div>
Expand Down
9 changes: 6 additions & 3 deletions src/manager/components/CommentForm/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default {
display: 'flex',
alignItems: 'center',
borderTop: '1px solid rgb(234, 234, 234)',
backgroundColor: '#fafafa',
},
loginButton: {
...button,
Expand All @@ -23,18 +24,20 @@ export default {
},
submitButton: {
...button,
borderLeft: '1px solid rgb(234, 234, 234)',
cursor: 'pointer',
},
input: {
flex: 1,
boxSizing: 'border-box',
height: 30,
maxHeight: 70,
border: 'none',
outline: 'none',
padding: '7px 15px',
padding: '5px 10px',
fontSize: 13,
lineHeight: 1.7,
lineHeight: 1.6,
color: 'rgba(0, 0, 0, 0.8)',
fontFamily: 'sans-serif',
resize: 'none',
},
}
3 changes: 2 additions & 1 deletion src/manager/components/CommentList/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from 'react';
import moment from 'moment';
import renderHTML from 'react-render-html';
import style from './style';

export default class CommentList extends Component {
Expand Down Expand Up @@ -38,7 +39,7 @@ export default class CommentList extends Component {
<span style={style.commentUser}>{comment.user.name}</span>
<span style={style.commentTime}>{this.formatTime(comment.time)}</span>
</div>
<span style={style.commentText}>{comment.text}</span>
<span style={style.commentText}>{ renderHTML(`<span>${comment.text}</span>`) }</span>
</div>
</div>
);
Expand Down

0 comments on commit 22478ab

Please sign in to comment.