2015-11-23 18:26:34 +01:00
|
|
|
var React = require('react')
|
|
|
|
var Markdown = require('markdown.jsx')
|
|
|
|
var Icon = require('icon.jsx')
|
2015-11-23 18:38:21 +01:00
|
|
|
var Clock = require('clock.jsx')
|
2015-11-26 19:04:47 +01:00
|
|
|
var Link = require('react-router').Link
|
2015-11-28 10:02:49 +01:00
|
|
|
var UserID = require('userID.jsx')
|
2015-11-23 18:26:34 +01:00
|
|
|
|
2015-11-28 10:02:49 +01:00
|
|
|
var Comment = React.createClass({
|
2015-12-18 22:22:26 +01:00
|
|
|
getInitialState () {
|
2015-11-28 10:02:49 +01:00
|
|
|
return { moment: false }
|
|
|
|
},
|
2015-12-18 22:22:26 +01:00
|
|
|
componentDidMount () {
|
2015-12-14 00:29:25 +01:00
|
|
|
require.ensure(['moment'], _ => {
|
|
|
|
if (this.isMounted()) this.setState({ moment: require('moment') })
|
2015-11-28 10:02:49 +01:00
|
|
|
})
|
|
|
|
},
|
2015-12-18 22:22:26 +01:00
|
|
|
getPermalink () {
|
2015-12-14 00:29:25 +01:00
|
|
|
if (this.props.adminID && this.props.board && this.props.post && this.props.comment.hash) {
|
2015-11-28 10:02:49 +01:00
|
|
|
return <div className="inline not-first">
|
2015-12-14 00:29:25 +01:00
|
|
|
<Icon name="code" /> <Link to={'/@' + this.props.adminID + '/' + this.props.board + '/' + this.props.post + '/' + this.props.comment.hash}>Permalink</Link>
|
2015-11-28 10:02:49 +01:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
},
|
2015-12-18 22:22:26 +01:00
|
|
|
getParentlink () {
|
2015-12-14 00:29:25 +01:00
|
|
|
if (this.props.showParent && this.props.comment.parent && this.props.comment.parent !== this.props.post) {
|
2015-11-28 10:02:49 +01:00
|
|
|
return <div className="inline not-first">
|
2015-12-14 00:29:25 +01:00
|
|
|
<Icon name="level-up" /> <Link to={'/@' + this.props.adminID + '/' + this.props.board + '/' + this.props.post + '/' + this.props.comment.parent}>Parent</Link>
|
2015-11-28 10:02:49 +01:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
},
|
2015-12-18 22:22:26 +01:00
|
|
|
getComments () {
|
2015-11-28 10:02:49 +01:00
|
|
|
return <Comments className="shifted" parent={this.props.comment.hash} post={this.props.post} adminID={this.props.adminID} board={this.props.board} api={this.props.api} />
|
|
|
|
},
|
2015-12-18 22:22:26 +01:00
|
|
|
render () {
|
2015-12-14 00:29:25 +01:00
|
|
|
if (this.props.comment) {
|
2015-11-28 10:02:49 +01:00
|
|
|
return <div className="comment"><hr/>
|
|
|
|
<div className="icons">
|
|
|
|
<UserID id={this.props.comment.op} api={this.props.api} />
|
|
|
|
<Clock date={this.props.comment.date} />
|
|
|
|
{this.getPermalink()}
|
|
|
|
{this.getParentlink()}
|
2015-11-26 19:04:47 +01:00
|
|
|
</div>
|
2015-11-28 10:02:49 +01:00
|
|
|
<Markdown source={this.props.comment.text} />
|
2015-11-28 10:18:06 +01:00
|
|
|
<hr/>{this.getComments()}</div>
|
2015-11-28 10:02:49 +01:00
|
|
|
} else {
|
|
|
|
return <div><hr/>Invalid Comment<hr/></div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
var Comments = React.createClass({
|
2015-12-18 22:22:26 +01:00
|
|
|
getInitialState () {
|
2015-11-28 10:02:49 +01:00
|
|
|
return { comments: [] }
|
|
|
|
},
|
2015-12-18 22:22:26 +01:00
|
|
|
componentDidMount () {
|
2015-11-28 10:02:49 +01:00
|
|
|
var boards = this.props.api
|
2015-12-14 00:29:25 +01:00
|
|
|
if (boards) {
|
|
|
|
boards.getEventEmitter().on('comment for ' + this.props.parent, cmnt => {
|
|
|
|
if (this.isMounted()) this.setState({ comments: this.state.comments.concat(cmnt) })
|
2015-11-28 10:02:49 +01:00
|
|
|
})
|
2015-12-14 00:29:25 +01:00
|
|
|
if (boards.isInit && this.isMounted()) {
|
|
|
|
boards.getCommentsFor(this.props.parent, this.props.board, this.props.adminID)
|
2015-11-26 19:04:47 +01:00
|
|
|
}
|
2015-11-28 10:02:49 +01:00
|
|
|
boards.getEventEmitter().on('init', err => {
|
2015-12-14 00:29:25 +01:00
|
|
|
if (!err && this.isMounted()) {
|
|
|
|
boards.getCommentsFor(this.props.parent, this.props.board, this.props.adminID)
|
|
|
|
}
|
2015-11-28 10:02:49 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2015-12-18 22:22:26 +01:00
|
|
|
getComments () {
|
2015-12-14 00:29:25 +01:00
|
|
|
if (this.state.comments.length > 0) {
|
|
|
|
return this.state.comments.map(cmnt => (<Comment key={cmnt.hash} comment={cmnt} post={this.props.post} adminID={this.props.adminID} board={this.props.board} api={this.props.api} />))
|
2015-11-23 18:26:34 +01:00
|
|
|
}
|
2015-11-28 10:02:49 +01:00
|
|
|
else return <div></div>
|
|
|
|
},
|
2015-12-18 22:22:26 +01:00
|
|
|
render () {
|
2015-12-14 00:29:25 +01:00
|
|
|
return <div className={this.props.className + ' comments'} >{this.getComments()}</div>
|
2015-11-28 10:02:49 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = { Comment, Comments }
|