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

another refactor, also closes #45

This commit is contained in:
Enrico Fasoli 2015-12-18 22:32:15 +01:00
parent 7c558e749b
commit d53ce31b51

View File

@ -5,24 +5,13 @@ var UserID = require('userID.jsx')
module.exports = function (boardsAPI) {
return React.createClass({
getInitialState: function () {
getInitialState () {
return { users: [], api: false }
},
componentDidMount: function () {
componentDidMount () {
boardsAPI.use(boards => {
boards.init()
if (boards.isInit) {
if (this.isMounted()) {
this.init(boards)
}
}
var ee = boards.getEventEmitter()
ee.on('init', e => {
if (!e && this.isMounted()) {
this.init(boards)
}
})
ee.on('user', (id) => {
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) })
@ -30,24 +19,22 @@ module.exports = function (boardsAPI) {
})
})
},
init: function (boards) {
if (this.isMounted() && !this.state.init) {
this.setState({ users: boards.getUsers(), api: true, init: true, boards: boards })
boards.searchUsers()
}
init (boards) {
this.setState({ users: boards.getUsers(), api: boards })
boards.searchUsers()
},
render: function () {
render () {
if (this.state.api) {
return <div>
<h1><Icon name="users" /> Users</h1>
<h1><Icon name="users" className="light" /> Users</h1>
<p>Found <b>{this.state.users.length}</b> users</p>
<ul>
{this.state.users.map(user => {
return <UserID key={user} id={user} api={this.state.boards} />
return <UserID key={user} id={user} api={this.state.api} />
})}
</ul>
</div>
} else return <GetIPFS api={this.state.boards} />
} else return <GetIPFS api={this.state.api} />
}
})
}