1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-25 14:54:19 +01:00
ipfs-boards/webapp/components/post.jsx

62 lines
2.0 KiB
React
Raw Normal View History

2015-11-20 20:21:54 +01:00
var React = require('react')
var Markdown = require('markdown.jsx')
var Icon = require('icon.jsx')
var Link = require('react-router').Link
var Clock = require('clock.jsx')
var UserID = require('userID.jsx')
2015-12-17 22:19:21 +01:00
var { Error, Loading } = require('status-components.jsx')
2015-11-20 20:21:54 +01:00
module.exports = React.createClass({
2015-12-17 22:19:21 +01:00
getInitialState () {
return { loading: true }
},
2015-12-17 22:19:21 +01:00
componentDidMount () {
this.init(this.props)
},
componentWillReceiveProps (props) {
this.init(props)
},
init (props) {
var boards = props.api
if (!boards) return this.setState({ error: 'Could not connect to IPFS' })
this.setState({ loading: true })
boards.downloadPost(props.hash, props.adminID, props.board, (err, hash, date, post) => {
this.setState({ error: err, post: post, loading: false })
})
},
2015-12-17 22:19:21 +01:00
postLink () {
if (this.state.post.op) {
if (this.props.board) {
2015-12-17 22:19:21 +01:00
return '/@' + this.state.post.op + '/' + this.props.board + '/' + this.props.hash
2015-11-23 13:00:49 +01:00
} else {
2015-12-17 22:19:21 +01:00
return '/@' + this.state.post.op + '/post/' + this.props.hash
2015-11-23 13:00:49 +01:00
}
} else {
2015-12-17 22:19:21 +01:00
return '/post/' + this.props.hash
}
},
2015-12-17 22:19:21 +01:00
getContent () {
if (this.state.error) {
return <Error className="content" error={this.state.error} />
} else if (this.state.loading) {
return <Loading className="content" title="Downloading post"/>
} else {
return <div className="content">
{ this.state.post.title
? <div><h5>{this.state.post.title}</h5><hr/></div>
: <div />
}
<Markdown source={this.state.post.text} /><hr/>
<div className="icons">
2015-12-17 22:19:21 +01:00
<UserID id={this.state.post.op} api={this.props.api} ></UserID>
<Clock className="not-first" date={this.state.post.date} />
<Icon name="comments" className="not-first" /> <Link className="nounderline" to={this.postLink()}>View</Link>
2015-11-20 20:21:54 +01:00
</div>
</div>
2015-12-17 22:19:21 +01:00
}
},
render () {
return <div className="post">{this.getContent()}</div>
}
})