1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-25 14:54:19 +01:00
ipfs-boards/webapp/pages/users.jsx

41 lines
1.2 KiB
React
Raw Normal View History

2015-11-20 20:21:54 +01:00
var React = require('react')
var Icon = require('icon.jsx')
var GetIPFS = require('getipfs.jsx')
var UserID = require('userID.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-18 22:32:15 +01:00
getInitialState () {
return { users: [], api: false }
2015-11-20 20:21:54 +01:00
},
2015-12-18 22:32:15 +01:00
componentDidMount () {
boardsAPI.use(boards => {
2015-12-18 22:32:15 +01:00
this.init(boards)
boards.getEventEmitter().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
})
},
2015-12-18 22:32:15 +01:00
init (boards) {
this.setState({ users: boards.getUsers(), api: boards })
boards.searchUsers()
},
2015-12-18 22:32:15 +01:00
render () {
if (this.state.api) {
return <div>
2015-12-18 22:32:15 +01:00
<h1><Icon name="users" className="light" /> Users</h1>
<p>Found <b>{this.state.users.length}</b> users</p>
<ul>
{this.state.users.map(user => {
2015-12-18 22:32:15 +01:00
return <UserID key={user} id={user} api={this.state.api} />
})}
</ul>
</div>
2015-12-18 22:32:15 +01:00
} else return <GetIPFS api={this.state.api} />
2015-11-20 20:21:54 +01:00
}
})
}