2015-11-20 20:21:54 +01:00
|
|
|
var React = require('react')
|
|
|
|
var Markdown = require('markdown.jsx')
|
|
|
|
var Icon = require('icon.jsx')
|
2015-11-22 00:10:46 +01:00
|
|
|
var Link = require('react-router').Link
|
2015-11-20 20:21:54 +01:00
|
|
|
|
2015-11-22 00:10:46 +01:00
|
|
|
module.exports = function(boardsAPI){
|
|
|
|
var UserID = require('userID.jsx')(boardsAPI)
|
2015-11-20 20:21:54 +01:00
|
|
|
return React.createClass({
|
|
|
|
getDate: function(){
|
|
|
|
if(this.props.post.date){
|
2015-11-22 00:10:46 +01:00
|
|
|
if(this.state.moment)
|
|
|
|
return this.state.moment.unix(this.props.post.date).fromNow()
|
|
|
|
else return '...'
|
2015-11-20 20:21:54 +01:00
|
|
|
} else {
|
|
|
|
return 'Unknown Date'
|
|
|
|
}
|
|
|
|
},
|
2015-11-22 00:10:46 +01:00
|
|
|
getInitialState: function(){
|
|
|
|
return { moment: false }
|
|
|
|
},
|
|
|
|
componentDidMount: function(){
|
|
|
|
require.ensure(['moment'],_ => {
|
|
|
|
if(this.isMounted()) this.setState({ moment: require('moment') })
|
|
|
|
})
|
|
|
|
},
|
2015-11-23 13:00:49 +01:00
|
|
|
postLink: function(){
|
|
|
|
console.log('op',this.props.post.op,'board',this.props.board)
|
|
|
|
if(this.props.post.op){
|
|
|
|
if(this.props.board){
|
|
|
|
return '/@'+this.props.post.op+'/'+this.props.board+'/'+this.props.post.hash
|
|
|
|
} else {
|
|
|
|
return '/@'+this.props.post.op+'/post/'+this.props.post.hash
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return '/post/'+this.props.post.hash
|
|
|
|
}
|
|
|
|
},
|
2015-11-20 20:21:54 +01:00
|
|
|
render: function(){
|
|
|
|
return <div key={this.props.post.title} className="post">
|
|
|
|
<div className="content">
|
|
|
|
<h5>{this.props.post.title}</h5><hr/>
|
|
|
|
<Markdown source={this.props.post.text} skipHtml={true} /><hr/>
|
|
|
|
<div className="icons">
|
|
|
|
<UserID id={this.props.post.op}></UserID>
|
|
|
|
<Icon name="clock-o" className="not-first"/> {this.getDate()}
|
2015-11-23 13:00:49 +01:00
|
|
|
<Icon name="comments" className="not-first" /> <Link to={this.postLink()}>View</Link>
|
2015-11-20 20:21:54 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|