-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComment.js
More file actions
46 lines (40 loc) · 1.49 KB
/
Copy pathComment.js
File metadata and controls
46 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var React = require('react'),
marked = require('marked'),
util = require('./util');
var Comment = React.createClass({
processContent: function(content) {
util.processContent(content, {
summaryMode: this.props.summaryMode
}, function(response) {
this.setState({
body: response
});
}.bind(this));
},
getInitialState: function() {
// since the passed props.data has not been processed yet, cannot show it right away
return {
body: ''
};
},
componentDidMount: function() {
this.processContent(this.props.data.body);
},
componentWillReceiveProps: function(nextProps) {
this.processContent(this.props.data.body);
},
render: function() {
//for summary mode, don't do markdown
var formmattedTime = (new Date(this.props.data.created_at)).toLocaleString().replace(', ', '@');
return (
<div className='comments-container'>
<a className='avatar-container' href={this.props.data.user.html_url}><img src={this.props.data.user.avatar_url + '&s=48'} className={'avatar'} /></a>
<a href={this.props.data.user.html_url}><span className='user-name'>{this.props.data.user.login}</span></a>
<span className='create-time'>{'said at ' + formmattedTime}</span>
<div className='caret comment-caret'></div>
<div className="comment-content" dangerouslySetInnerHTML={{__html: this.props.summaryMode? this.state.body: marked(this.state.body, {breaks: true})}}/>
</div>
);
}
});
module.exports = Comment;