1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-10 12:24:20 +01:00
ipfs-boards/webapp/components/comment.jsx

51 lines
1.9 KiB
React
Raw Normal View History

2015-11-23 18:26:34 +01:00
var React = require('react')
var Markdown = require('markdown.jsx')
var Icon = require('icon.jsx')
var Clock = require('clock.jsx')
2015-11-26 19:04:47 +01:00
var Link = require('react-router').Link
2015-11-23 18:26:34 +01:00
module.exports = function(boardsAPI){
var UserID = require('userID.jsx')(boardsAPI)
return React.createClass({
getInitialState: function(){
return { moment: false }
},
componentDidMount: function(){
require.ensure(['moment'],_ => {
if(this.isMounted()) this.setState({ moment: require('moment') })
})
},
2015-11-26 19:04:47 +01:00
getPermalink: function(){
if(this.props.adminID && this.props.board && this.props.post && this.props.comment.hash){
return <div className="inline not-first">
<Icon name="code" /> <Link to={'/@'+this.props.adminID+'/'+this.props.board+'/'+this.props.post+'/'+this.props.comment.hash}>Permalink</Link>
</div>
}
},
getParentlink: function(){
if(this.props.showParent && this.props.comment.parent && this.props.comment.parent !== this.props.post){
return <div className="inline not-first">
<Icon name="level-up" /> <Link to={'/@'+this.props.adminID+'/'+this.props.board+'/'+this.props.post+'/'+this.props.comment.parent}>Parent</Link>
</div>
}
},
2015-11-23 18:26:34 +01:00
render: function(){
if(this.props.comment){
var Comments = this.props.comment.comments || require('comments.jsx')(boardsAPI)
2015-11-23 18:26:34 +01:00
return <div className="comment"><hr/>
<div className="icons">
<UserID id={this.props.comment.op} />
<Clock date={this.props.comment.date} />
2015-11-26 19:04:47 +01:00
{this.getPermalink()}
{this.getParentlink()}
2015-11-23 18:26:34 +01:00
</div>
<Markdown source={this.props.comment.text} />
2015-11-26 19:04:47 +01:00
<Comments className="shifted" parent={this.props.comment.hash} post={this.props.post} adminID={this.props.adminID} board={this.props.board}/>
2015-11-23 18:26:34 +01:00
<hr/></div>
} else {
return <div><hr/>Invalid Comment<hr/></div>
}
}
})
}