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

61 lines
1.5 KiB
React
Raw Normal View History

2015-11-20 20:21:54 +01:00
var React = require('react')
var Icon = require('icon.jsx')
var Link = require('react-router').Link
module.exports = React.createClass({
2015-12-18 22:22:26 +01:00
getInitialState () {
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
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-12-18 22:22:26 +01:00
getProfile (boards) {
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 {
this.setState({ name: res.name || 'Unknown Name' })
2015-11-20 20:21:54 +01:00
}
})
},
2015-12-18 22:22:26 +01:00
getContent () {
if (this.state.name) {
return (<Icon name="user" />)
} else {
return '@'
2015-11-20 20:21:54 +01:00
}
},
2015-12-18 22:22:26 +01:00
render () {
if (this.props.id === undefined || this.props.id === 'undefined') {
return <div className="user-id">
<Icon name="ban" /> Unknown User
</div>
} else {
return (<div className="user-id">
<Link className="light nounderline" to={'/@' + this.props.id}>
{this.getContent()}{this.state.name || this.props.id}
</Link>
</div>)
}
}
})