2015-11-22 00:10:46 +01:00
|
|
|
var React = require('react')
|
|
|
|
|
2015-11-23 13:00:49 +01:00
|
|
|
module.exports = function(boardsAPI){
|
|
|
|
var UserID = require('userID.jsx')(boardsAPI)
|
|
|
|
var GetIPFS = require('getipfs.jsx')(boardsAPI)
|
|
|
|
var Post = require('post.jsx')(boardsAPI)
|
2015-11-22 00:10:46 +01:00
|
|
|
return React.createClass({
|
|
|
|
getInitialState: function(){
|
2015-11-23 13:00:49 +01:00
|
|
|
return { post: { title: '...', text: '...' }, api: false }
|
2015-11-22 00:10:46 +01:00
|
|
|
},
|
|
|
|
componentDidMount: function(){
|
2015-11-23 13:00:49 +01:00
|
|
|
boardsAPI.use(boards => {
|
|
|
|
boards.getEventEmitter().on('init', err => {
|
|
|
|
if(!err && this.isMounted()){
|
|
|
|
this.init(boards)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if(this.isMounted() && boards.isInit){
|
|
|
|
this.init(boards)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
init: function(boards){
|
|
|
|
if(this.state.init) return
|
|
|
|
this.setState({ api: true })
|
|
|
|
boards.downloadPost(this.props.params.posthash,this.props.params.userid,this.props.params.boardname,this.props.params.userid,(err,post) => {
|
2015-11-22 00:10:46 +01:00
|
|
|
if(err){
|
2015-11-23 13:00:49 +01:00
|
|
|
this.setState({ post: { title: 'Error', text: err.Message || err.Error }})
|
2015-11-22 00:10:46 +01:00
|
|
|
} else {
|
|
|
|
this.setState({ post })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
render: function(){
|
2015-11-23 13:00:49 +01:00
|
|
|
if(this.state.api)
|
|
|
|
return <Post post={this.state.post} board={this.props.params.boardname} />
|
2015-11-22 00:10:46 +01:00
|
|
|
else return <GetIPFS />
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|