2015-11-20 20:21:54 +01:00
|
|
|
var React = require('react')
|
|
|
|
var Markdown = require('markdown.jsx')
|
|
|
|
var Link = require('react-router').Link
|
|
|
|
var Icon = require('icon.jsx')
|
2015-11-28 10:18:06 +01:00
|
|
|
var GetIPFS = require('getipfs.jsx')
|
2015-12-17 18:43:10 +01:00
|
|
|
var { Loading, Error } = require('status-components.jsx')
|
2015-11-20 20:21:54 +01:00
|
|
|
|
2015-12-14 00:29:25 +01:00
|
|
|
module.exports = function (boardsAPI) {
|
2015-11-20 20:21:54 +01:00
|
|
|
return React.createClass({
|
2015-12-17 18:43:10 +01:00
|
|
|
getInitialState () {
|
|
|
|
return { loading: true, boards: [], api: false }
|
2015-11-20 20:21:54 +01:00
|
|
|
},
|
2015-12-17 18:43:10 +01:00
|
|
|
componentDidMount () {
|
2015-11-22 00:10:46 +01:00
|
|
|
boardsAPI.use(boards => {
|
2015-12-19 17:43:55 +01:00
|
|
|
if (boards.isInit || boards.limited) {
|
2015-12-10 21:15:26 +01:00
|
|
|
this.init(boards)
|
2015-11-22 00:10:46 +01:00
|
|
|
}
|
|
|
|
var ee = boards.getEventEmitter()
|
2015-12-19 17:43:55 +01:00
|
|
|
ee.on('init', (err, limited) => {
|
|
|
|
if ((!err || limited) && this.isMounted()) {
|
2015-12-10 21:15:26 +01:00
|
|
|
this.init(boards)
|
2015-11-22 00:10:46 +01:00
|
|
|
}
|
|
|
|
})
|
2015-11-20 20:21:54 +01:00
|
|
|
})
|
2015-11-22 00:10:46 +01:00
|
|
|
},
|
2015-12-17 18:43:10 +01:00
|
|
|
componentWillReceiveProps (nextProps) {
|
2015-12-14 00:29:25 +01:00
|
|
|
boardsAPI.use(boards => this.downloadProfile(boards, nextProps))
|
2015-12-17 18:43:10 +01:00
|
|
|
this.setState({ loading: true })
|
2015-12-10 21:15:26 +01:00
|
|
|
},
|
2015-12-17 18:43:10 +01:00
|
|
|
downloadProfile (boards, props) {
|
2015-12-10 21:15:26 +01:00
|
|
|
var ee = boards.getEventEmitter()
|
|
|
|
var uid = props.params.userid
|
2015-12-14 00:29:25 +01:00
|
|
|
ee.on('boards for ' + uid, l => {
|
2015-12-10 21:21:04 +01:00
|
|
|
var u2id = props.params.userid
|
2015-12-14 00:29:25 +01:00
|
|
|
if (!this.isMounted() || u2id !== uid) return true
|
2015-12-10 21:15:26 +01:00
|
|
|
this.setState({ boards: l })
|
|
|
|
})
|
2015-12-14 00:29:25 +01:00
|
|
|
boards.getProfile(uid, (err, res) => {
|
|
|
|
if (!this.isMounted()) return true
|
|
|
|
if (err) {
|
2015-12-17 18:43:10 +01:00
|
|
|
this.setState({ loading: false, error: err })
|
2015-12-10 21:15:26 +01:00
|
|
|
} else {
|
2015-12-17 18:43:10 +01:00
|
|
|
this.setState({ loading: false, name: res.name, description: res.description })
|
2015-11-20 20:21:54 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2015-12-17 18:43:10 +01:00
|
|
|
init (boards) {
|
2015-12-14 00:29:25 +01:00
|
|
|
if (this.state.init) return
|
2015-12-19 17:43:55 +01:00
|
|
|
this.setState({ init: true, api: boards, id: boards.id, limited: boards.limited })
|
2015-12-18 19:48:49 +01:00
|
|
|
this.downloadProfile(boards, this.props)
|
2015-12-10 21:15:26 +01:00
|
|
|
},
|
2015-12-17 18:43:10 +01:00
|
|
|
linkToEditor () {
|
2015-11-22 00:10:46 +01:00
|
|
|
var uid = this.props.params.userid
|
2015-12-14 00:29:25 +01:00
|
|
|
if (uid === this.state.id) {
|
2015-12-12 17:51:03 +01:00
|
|
|
return <div className="your-profile">
|
2015-11-20 20:21:54 +01:00
|
|
|
<h6>This is your profile</h6>
|
2015-12-15 21:47:26 +01:00
|
|
|
<div className="iconbar">
|
|
|
|
<Link className="nounderline" to="/edit/profile"><Icon name="edit" className="fa-2x light"/></Link>
|
|
|
|
</div>
|
2015-11-20 20:21:54 +01:00
|
|
|
<hr/>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
return ''
|
|
|
|
},
|
2015-12-17 18:43:10 +01:00
|
|
|
getEditButton () {
|
|
|
|
return <Link className="button button-primary" to="/edit/profile">Edit Profile</Link>
|
|
|
|
},
|
|
|
|
render () {
|
2015-12-14 00:29:25 +01:00
|
|
|
if (this.state.api) {
|
2015-12-17 18:43:10 +01:00
|
|
|
if (this.state.error) {
|
|
|
|
return <Error error={this.state.error}>{this.getEditButton()}</Error>
|
|
|
|
} else if (this.state.loading) {
|
|
|
|
return <Loading title="Downloading Profile">{this.getEditButton()}</Loading>
|
|
|
|
} else {
|
|
|
|
var uid = this.props.params.userid
|
|
|
|
return (<div className="profile">
|
|
|
|
{this.linkToEditor()}
|
|
|
|
<h1>{this.state.name}</h1>
|
|
|
|
<Markdown source={this.state.description} skipHtml={true} />
|
|
|
|
<hr/>
|
|
|
|
<div className="light breaker">@{uid}</div>
|
|
|
|
{this.state.boards.map(n => {
|
|
|
|
return <h6 className="light" key={uid + '/' + n.name}>
|
|
|
|
<Link to={'/@' + uid + '/' + n.name}># {n.name}</Link>
|
|
|
|
</h6>
|
|
|
|
})}
|
|
|
|
</div>)
|
|
|
|
}
|
2015-11-28 10:02:49 +01:00
|
|
|
} else return <GetIPFS api={this.state.api} />
|
2015-11-20 20:21:54 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|