mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-01-25 14:54:19 +01:00
another refactor, also closes #45
This commit is contained in:
parent
7c558e749b
commit
d53ce31b51
@ -5,24 +5,13 @@ var UserID = require('userID.jsx')
|
|||||||
|
|
||||||
module.exports = function (boardsAPI) {
|
module.exports = function (boardsAPI) {
|
||||||
return React.createClass({
|
return React.createClass({
|
||||||
getInitialState: function () {
|
getInitialState () {
|
||||||
return { users: [], api: false }
|
return { users: [], api: false }
|
||||||
},
|
},
|
||||||
componentDidMount: function () {
|
componentDidMount () {
|
||||||
boardsAPI.use(boards => {
|
boardsAPI.use(boards => {
|
||||||
boards.init()
|
|
||||||
if (boards.isInit) {
|
|
||||||
if (this.isMounted()) {
|
|
||||||
this.init(boards)
|
this.init(boards)
|
||||||
}
|
boards.getEventEmitter().on('user', (id) => {
|
||||||
}
|
|
||||||
var ee = boards.getEventEmitter()
|
|
||||||
ee.on('init', e => {
|
|
||||||
if (!e && this.isMounted()) {
|
|
||||||
this.init(boards)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
ee.on('user', (id) => {
|
|
||||||
if (id === undefined || id === 'undefined') console.log('found undefined user???')
|
if (id === undefined || id === 'undefined') console.log('found undefined user???')
|
||||||
if (this.isMounted() && this.state.users.indexOf(id) < 0) {
|
if (this.isMounted() && this.state.users.indexOf(id) < 0) {
|
||||||
this.setState({ users: this.state.users.concat(id) })
|
this.setState({ users: this.state.users.concat(id) })
|
||||||
@ -30,24 +19,22 @@ module.exports = function (boardsAPI) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
init: function (boards) {
|
init (boards) {
|
||||||
if (this.isMounted() && !this.state.init) {
|
this.setState({ users: boards.getUsers(), api: boards })
|
||||||
this.setState({ users: boards.getUsers(), api: true, init: true, boards: boards })
|
|
||||||
boards.searchUsers()
|
boards.searchUsers()
|
||||||
}
|
|
||||||
},
|
},
|
||||||
render: function () {
|
render () {
|
||||||
if (this.state.api) {
|
if (this.state.api) {
|
||||||
return <div>
|
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>
|
<p>Found <b>{this.state.users.length}</b> users</p>
|
||||||
<ul>
|
<ul>
|
||||||
{this.state.users.map(user => {
|
{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>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
} else return <GetIPFS api={this.state.boards} />
|
} else return <GetIPFS api={this.state.api} />
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user