2015-11-20 20:21:54 +01:00
|
|
|
var React = require('react')
|
|
|
|
var Icon = require('icon.jsx')
|
|
|
|
var Link = require('react-router').Link
|
|
|
|
|
2015-11-28 10:18:06 +01:00
|
|
|
module.exports = React.createClass({
|
2015-12-18 22:22:26 +01:00
|
|
|
getInitialState () {
|
2015-11-28 10:18:06 +01:00
|
|
|
return { }
|
|
|
|
},
|
2015-12-18 22:22:26 +01:00
|
|
|
componentWillReceiveProps (props) {
|
|
|
|
this.init(props)
|
|
|
|
},
|
|
|
|
componentDidMount () {
|
|
|
|
this.init()
|
|
|
|
},
|
|
|
|
init (props) {
|
|
|
|
props = props || this.props
|
|
|
|
var boards = props.api
|
2015-12-14 00:29:25 +01:00
|
|
|
if (boards) {
|
2015-12-19 17:43:55 +01:00
|
|
|
boards.getEventEmitter().on('init', (err, limited) => {
|
|
|
|
if ((!err || limited) && this.isMounted()) {
|
|
|
|
this.getProfile(boards)
|
|
|
|
}
|
2015-11-20 20:21:54 +01:00
|
|
|
})
|
2015-12-19 17:43:55 +01:00
|
|
|
if (boards.isInit || boards.limited) {
|
2015-12-18 22:22:26 +01:00
|
|
|
this.getProfile(boards)
|
|
|
|
}
|
2015-11-28 10:18:06 +01:00
|
|
|
}
|
|
|
|
},
|
2015-12-18 22:22:26 +01:00
|
|
|
getProfile (boards) {
|
2015-12-14 00:29:25 +01:00
|
|
|
if (this.props.id === undefined) return
|
|
|
|
boards.getProfile(this.props.id, (err, res) => {
|
|
|
|
if (!this.isMounted()) return true
|
|
|
|
if (err) {
|
|
|
|
console.log('Error while resolving user badge:', err)
|
2015-11-20 20:21:54 +01:00
|
|
|
} else {
|
2015-11-28 10:18:06 +01:00
|
|
|
this.setState({ name: res.name || 'Unknown Name' })
|
2015-11-20 20:21:54 +01:00
|
|
|
}
|
2015-11-28 10:18:06 +01:00
|
|
|
})
|
|
|
|
},
|
2015-12-18 22:22:26 +01:00
|
|
|
getContent () {
|
2015-12-14 00:29:25 +01:00
|
|
|
if (this.state.name) {
|
2015-11-28 10:18:06 +01:00
|
|
|
return (<Icon name="user" />)
|
|
|
|
} else {
|
|
|
|
return '@'
|
2015-11-20 20:21:54 +01:00
|
|
|
}
|
2015-11-28 10:18:06 +01:00
|
|
|
},
|
2015-12-18 22:22:26 +01:00
|
|
|
render () {
|
2015-12-14 00:29:25 +01:00
|
|
|
if (this.props.id === undefined || this.props.id === 'undefined') {
|
2015-11-28 10:18:06 +01:00
|
|
|
return <div className="user-id">
|
|
|
|
<Icon name="ban" /> Unknown User
|
|
|
|
</div>
|
2015-12-14 00:29:25 +01:00
|
|
|
} else {
|
2015-11-28 10:18:06 +01:00
|
|
|
return (<div className="user-id">
|
2015-12-14 00:29:25 +01:00
|
|
|
<Link className="light nounderline" to={'/@' + this.props.id}>
|
2015-11-28 10:18:06 +01:00
|
|
|
{this.getContent()}{this.state.name || this.props.id}
|
|
|
|
</Link>
|
|
|
|
</div>)
|
2015-12-14 00:29:25 +01:00
|
|
|
}
|
2015-11-28 10:18:06 +01:00
|
|
|
}
|
|
|
|
})
|