2015-11-22 00:10:46 +01:00
|
|
|
var React = require('react')
|
2015-11-23 16:07:04 +01:00
|
|
|
var Link = require('react-router').Link
|
2015-11-28 10:18:06 +01:00
|
|
|
var UserID = require('userID.jsx')
|
|
|
|
var GetIPFS = require('getipfs.jsx')
|
|
|
|
var Post = require('post.jsx')
|
|
|
|
var Comments = require('comment.jsx').Comments
|
2015-11-22 00:10:46 +01:00
|
|
|
|
2015-12-14 00:29:25 +01:00
|
|
|
module.exports = function (boardsAPI) {
|
2015-11-22 00:10:46 +01:00
|
|
|
return React.createClass({
|
2015-12-14 00:29:25 +01:00
|
|
|
getInitialState: function () {
|
2015-11-23 13:00:49 +01:00
|
|
|
return { post: { title: '...', text: '...' }, api: false }
|
2015-11-22 00:10:46 +01:00
|
|
|
},
|
2015-12-14 00:29:25 +01:00
|
|
|
componentDidMount: function () {
|
2015-11-23 13:00:49 +01:00
|
|
|
boardsAPI.use(boards => {
|
2015-11-23 16:07:04 +01:00
|
|
|
boards.init()
|
2015-11-23 13:00:49 +01:00
|
|
|
boards.getEventEmitter().on('init', err => {
|
2015-12-14 00:29:25 +01:00
|
|
|
if (!err && this.isMounted()) {
|
2015-11-23 13:00:49 +01:00
|
|
|
this.init(boards)
|
|
|
|
}
|
|
|
|
})
|
2015-12-14 00:29:25 +01:00
|
|
|
if (this.isMounted() && boards.isInit) {
|
2015-11-23 13:00:49 +01:00
|
|
|
this.init(boards)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2015-12-14 00:29:25 +01:00
|
|
|
componentWillReceiveProps: function (nextProps) {
|
|
|
|
boardsAPI.use(boards => this.downloadPost(boards, nextProps))
|
2015-12-10 21:15:26 +01:00
|
|
|
},
|
2015-12-14 00:29:25 +01:00
|
|
|
downloadPost: function (boards, props) {
|
|
|
|
boards.downloadPost(props.params.posthash, props.params.userid, props.params.boardname, props.params.userid, (err, post) => {
|
|
|
|
if (err) {
|
|
|
|
this.setState({
|
|
|
|
post: { title: 'Error', text: err.Message || err.Error }
|
|
|
|
})
|
2015-11-22 00:10:46 +01:00
|
|
|
} else {
|
|
|
|
this.setState({ post })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2015-12-14 00:29:25 +01:00
|
|
|
init: function (boards) {
|
|
|
|
if (this.state.init) return
|
2015-12-10 21:15:26 +01:00
|
|
|
this.setState({ api: true, boards: boards })
|
2015-12-14 00:29:25 +01:00
|
|
|
this.downloadPost(boards, this.props)
|
2015-12-10 21:15:26 +01:00
|
|
|
},
|
2015-12-14 00:29:25 +01:00
|
|
|
getContext: function () {
|
|
|
|
if (this.props.params.userid) {
|
|
|
|
if (this.props.params.boardname) {
|
|
|
|
return <div>Posted by <UserID id={this.props.params.userid} api={this.state.boards} /> in <Link to={'@' + this.props.params.userid + '/' + this.props.params.boardname}>#{this.props.params.boardname}</Link></div>
|
|
|
|
} else {
|
2015-11-28 10:02:49 +01:00
|
|
|
return <div>Posted by <UserID id={this.props.params.userid} api={this.state.boards} /></div>
|
2015-12-14 00:29:25 +01:00
|
|
|
}
|
2015-11-23 16:07:04 +01:00
|
|
|
} else return <div><h6 className="light">You are viewing a single post</h6></div>
|
|
|
|
},
|
2015-12-14 00:29:25 +01:00
|
|
|
render: function () {
|
|
|
|
if (this.state.api) {
|
2015-11-23 16:07:04 +01:00
|
|
|
return <div className="post-page">
|
|
|
|
<div className="text-center">
|
|
|
|
{this.getContext()}
|
|
|
|
</div>
|
2015-11-28 10:02:49 +01:00
|
|
|
<Post post={this.state.post} board={this.props.params.boardname} api={this.state.boards} />
|
|
|
|
<Comments parent={this.props.params.posthash} board={this.props.params.boardname} adminID={this.props.params.userid} post={this.props.params.posthash} api={this.state.boards} />
|
2015-11-23 16:07:04 +01:00
|
|
|
</div>
|
2015-12-14 00:29:25 +01:00
|
|
|
} else {
|
|
|
|
return <GetIPFS api={this.state.boards} />
|
|
|
|
}
|
2015-11-22 00:10:46 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|