1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-10 12:24:20 +01:00
ipfs-boards/webapp/pages/board.jsx

86 lines
3.5 KiB
React
Raw Normal View History

2015-11-20 20:21:54 +01:00
var React = require('react')
var Markdown = require('markdown.jsx')
var UserID = require('userID.jsx')
var PostList = require('postlist.jsx')
var GetIPFS = require('getipfs.jsx')
2015-12-17 16:18:07 +01:00
var Link = require('react-router').Link
var Icon = require('icon.jsx')
var {Loading} = require('status-components.jsx')
2015-11-20 20:21:54 +01:00
module.exports = function (boardsAPI) {
2015-11-20 20:21:54 +01:00
return React.createClass({
2015-12-17 16:18:07 +01:00
getInitialState () {
return { loading: true, whitelist: [] }
2015-11-20 20:21:54 +01:00
},
2015-12-17 16:18:07 +01:00
componentDidMount () {
boardsAPI.use(boards => {
if (!this.isMounted()) return
var ee = boards.getEventEmitter()
2015-12-19 17:43:55 +01:00
ee.on('init', (err, limited) => {
if ((!err || limited) && this.isMounted()) {
this.init(boards)
}
})
if (this.props.params.userid) {
ee.on('whitelist for ' + this.props.params.boardname + '@' + this.props.params.userid, (whitelist) => {
if (this.isMounted()) {
this.setState({ whitelist })
} else return true
})
ee.on('settings for ' + this.props.params.boardname + '@' + this.props.params.userid, (res) => {
if (!this.isMounted()) return true
2015-12-17 16:18:07 +01:00
if (res) this.setState({ loading: false, name: res.fullname, description: res.description })
2015-11-26 18:21:28 +01:00
})
} else {
2015-12-17 16:18:07 +01:00
this.setState({ loading: false, description: 'All the messages posted in __#' + this.props.params.boardname + '__' })
2015-11-26 18:21:28 +01:00
}
if (boards.isInit || this.state.api) {
this.init(boards)
}
2015-11-20 20:21:54 +01:00
})
},
componentWillReceiveProps (props) {
boardsAPI.use(b => this.init(b, props))
},
init (boards, newProps) {
var props = newProps || this.props
if (!props.params.userid) return
boards.getBoardSettings(props.params.userid, props.params.boardname)
2015-12-19 17:43:55 +01:00
this.setState({ loading: true, init: true, api: boards, userid: boards.getMyID(), limited: boards.limited })
},
2015-12-17 16:18:07 +01:00
toolbox () {
2015-12-19 17:43:55 +01:00
if (this.state.limited) {
return <div className="text-center">Toolbox not available in limited mode<hr/></div>
} else {
return <div className="iconbar text-center">
<Link to={'/edit/board/' + this.props.params.boardname} ><Icon name="edit" className="fa-2x light" /></Link>
<Link to={'/edit/board/' + this.props.params.boardname + '/post'} ><Icon name="plus" className="fa-2x light" /></Link>
</div>
}
2015-12-17 16:18:07 +01:00
},
render () {
if (this.state.api) {
2015-12-17 16:18:07 +01:00
if (this.state.loading) {
return <Loading title="Downloading Board data">
{ this.props.params.userid === 'me' || this.props.params.userid === this.state.userid
? <Link to={'/edit/board/' + this.props.params.boardname} className="button button-primary">Edit Board</Link>
: <span></span> }
</Loading>
2015-12-17 16:18:07 +01:00
} else {
return (<div className="board">
<h2>{this.state.name}</h2>
<Markdown source={this.state.description} skipHtml={true} />
2015-12-19 17:43:55 +01:00
{this.props.params.userid ? <h5><UserID id={this.props.params.userid} api={this.state.api} /></h5> : <p></p>}
2015-12-17 16:18:07 +01:00
<div className="whitelist">
2015-12-19 17:43:55 +01:00
{this.state.whitelist.map(i => <UserID id={i} key={i} api={this.state.api} />)}
2015-12-17 16:18:07 +01:00
</div>
<hr />
{this.toolbox()}
2015-12-19 17:43:55 +01:00
<PostList board={this.props.params.boardname} admin={this.props.params.userid} api={this.state.api} />
2015-12-17 16:18:07 +01:00
</div>)
}
2015-12-19 17:43:55 +01:00
} else return <GetIPFS api={this.state.api} />
2015-11-20 20:21:54 +01:00
}
})
}