mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-01-11 12:34:20 +01:00
31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
var React = require('react')
|
|
|
|
module.exports = function(boardsAPI){
|
|
var Comment = require('comment.jsx')(boardsAPI)
|
|
return React.createClass({
|
|
getInitialState: function(){
|
|
return { comments: [] }
|
|
},
|
|
componentDidMount: function(){
|
|
boardsAPI.use(boards => {
|
|
boards.getEventEmitter().on('comment for '+this.props.parent,cmnt => {
|
|
if(this.isMounted()) this.setState({ comments: this.state.comments.concat(cmnt) })
|
|
})
|
|
if(boards.isInit && this.isMounted()){
|
|
boards.getCommentsFor(this.props.parent,this.props.board,this.props.adminID)
|
|
}
|
|
boards.getEventEmitter().on('init', err => {
|
|
if(!err && this.isMounted())
|
|
boards.getCommentsFor(this.props.parent,this.props.board,this.props.adminID)
|
|
})
|
|
})
|
|
},
|
|
getComments: function(){
|
|
return this.state.comments.map(cmnt => (<Comment key={cmnt.hash} comment={cmnt} />) )
|
|
},
|
|
render: function(){
|
|
return <div>{this.getComments()}</div>
|
|
}
|
|
})
|
|
}
|