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

56 lines
1.6 KiB
React
Raw Normal View History

2015-11-20 20:21:54 +01:00
var React = require('react')
var Icon = require('icon.jsx')
module.exports = function(boardsAPI){
var GetIPFS = require('getipfs.jsx')(boardsAPI)
var UserID = require('userID.jsx')(boardsAPI)
2015-11-20 20:21:54 +01:00
return React.createClass({
getInitialState: function(){
return { users: [], api: false }
2015-11-20 20:21:54 +01:00
},
componentDidMount: function(){
boardsAPI.use(boards => {
boards.init()
if(boards.isInit){
if(this.isMounted()){
this.setState({ api: true })
this.init(boards)
}
}
var ee = boards.getEventEmitter()
ee.on('init', e => {
if(!e && this.isMounted()){
this.init(boards)
this.setState({ api: true })
}
})
ee.on('user',(id) => {
if(id === undefined || id === 'undefined') console.log('found undefined user???')
if(this.isMounted() && this.state.users.indexOf(id) < 0){
this.setState({ users: this.state.users.concat(id) })
}
})
2015-11-20 20:21:54 +01:00
})
},
init: function(boards){
if(this.isMounted() && !this.state.init){
this.setState({ users: boards.getUsers(), init: true })
boards.searchUsers()
}
},
2015-11-20 20:21:54 +01:00
render: function(){
if(this.state.api){
return <div>
<h1><Icon name="users" /> Users</h1>
<p>Found <b>{this.state.users.length}</b> users</p>
<ul>
{this.state.users.map(user => {
return <UserID key={user} id={user} />
})}
</ul>
</div>
} else return <GetIPFS />
2015-11-20 20:21:54 +01:00
}
})
}