2015-11-20 20:21:54 +01:00
|
|
|
var React = require('react')
|
|
|
|
var Markdown = require('markdown.jsx')
|
2015-11-28 10:18:06 +01:00
|
|
|
var UserID = require('userID.jsx')
|
|
|
|
var PostList = require('postlist.jsx')
|
|
|
|
var GetIPFS = require('getipfs.jsx')
|
2015-11-20 20:21:54 +01:00
|
|
|
|
2015-12-14 00:29:25 +01:00
|
|
|
module.exports = function (boardsAPI) {
|
2015-11-20 20:21:54 +01:00
|
|
|
return React.createClass({
|
2015-12-14 00:29:25 +01:00
|
|
|
getInitialState: function () {
|
2015-12-04 11:41:37 +01:00
|
|
|
return { name: this.props.params.boardname, api: false, whitelist: [] }
|
2015-11-20 20:21:54 +01:00
|
|
|
},
|
2015-12-14 00:29:25 +01:00
|
|
|
componentDidMount: function () {
|
2015-11-22 00:10:46 +01:00
|
|
|
boardsAPI.use(boards => {
|
|
|
|
/*
|
|
|
|
When a component inside the component being rendered by the router also needs
|
|
|
|
access to the boards api, it appears unitialized and never initializes to it
|
|
|
|
for no apparent reason. Calling init twice (one automgically and one
|
|
|
|
when the root component mounts) works as a cheap, horrible workaround
|
|
|
|
*/
|
|
|
|
boards.init()
|
2015-12-14 00:29:25 +01:00
|
|
|
if (!this.isMounted()) return
|
2015-11-22 00:10:46 +01:00
|
|
|
var ee = boards.getEventEmitter()
|
2015-12-14 00:29:25 +01:00
|
|
|
ee.on('init', err => {
|
|
|
|
if (!err && this.isMounted()) {
|
2015-11-22 00:10:46 +01:00
|
|
|
this.init(boards)
|
|
|
|
}
|
|
|
|
})
|
2015-12-14 00:29:25 +01:00
|
|
|
if (this.props.params.userid) {
|
|
|
|
ee.on('whitelist for ' + this.props.params.boardname + '@' + this.props.params.userid, (whitelist) => {
|
|
|
|
if (this.isMounted()) {
|
2015-12-10 21:15:02 +01:00
|
|
|
this.setState({ whitelist })
|
2015-12-14 00:29:25 +01:00
|
|
|
} else return true
|
2015-12-04 11:41:37 +01:00
|
|
|
})
|
2015-12-14 00:29:25 +01:00
|
|
|
ee.on('settings for ' + this.props.params.boardname + '@' + this.props.params.userid, (res) => {
|
|
|
|
if (!this.isMounted()) return true
|
|
|
|
if (res) this.setState({ name: res.fullname, description: res.description })
|
2015-11-26 18:21:28 +01:00
|
|
|
})
|
|
|
|
} else {
|
2015-12-14 00:29:25 +01:00
|
|
|
this.setState({ description: 'All the messages posted in __#' + this.props.params.boardname + '__' })
|
2015-11-26 18:21:28 +01:00
|
|
|
}
|
2015-12-14 00:29:25 +01:00
|
|
|
if (boards.isInit || this.state.api) {
|
2015-11-22 00:10:46 +01:00
|
|
|
this.init(boards)
|
|
|
|
}
|
2015-11-20 20:21:54 +01:00
|
|
|
})
|
|
|
|
},
|
2015-12-14 00:29:25 +01:00
|
|
|
init: function (boards) {
|
|
|
|
if (!this.state.init) {
|
|
|
|
if (this.props.params.userid) {
|
|
|
|
boards.getBoardSettings(this.props.params.userid, this.props.params.boardname)
|
|
|
|
}
|
2015-11-28 10:02:49 +01:00
|
|
|
this.setState({ init: true, api: true, boards: boards })
|
2015-11-22 00:10:46 +01:00
|
|
|
}
|
|
|
|
},
|
2015-12-14 00:29:25 +01:00
|
|
|
render: function () {
|
|
|
|
if (this.state.api) {
|
2015-11-22 00:10:46 +01:00
|
|
|
return (<div className="board">
|
|
|
|
<h2>{this.state.name}</h2>
|
|
|
|
<Markdown source={this.state.description} skipHtml={true} />
|
2015-12-14 00:29:25 +01:00
|
|
|
{this.props.params.userid ? <h5><UserID id={this.props.params.userid} api={this.state.boards} /></h5> : <p></p>}
|
2015-12-04 11:41:37 +01:00
|
|
|
<div className="whitelist">
|
2015-12-12 11:57:51 +01:00
|
|
|
{this.state.whitelist.map(i => <UserID id={i} key={i} api={this.state.boards} />)}
|
2015-12-04 11:41:37 +01:00
|
|
|
</div>
|
2015-11-26 18:21:28 +01:00
|
|
|
<hr />
|
2015-11-28 10:02:49 +01:00
|
|
|
<PostList board={this.props.params.boardname} admin={this.props.params.userid} api={this.state.boards} />
|
2015-11-22 00:10:46 +01:00
|
|
|
</div>)
|
2015-11-28 10:02:49 +01:00
|
|
|
} else return <GetIPFS api={this.state.boards} />
|
2015-11-20 20:21:54 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|