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

80 lines
2.8 KiB
React
Raw Normal View History

var React = require('react')
var Icon = require('icon.jsx')
var Link = require('react-router').Link
2015-12-15 17:15:12 +01:00
var Updater = React.createClass({
2015-12-22 14:49:29 +01:00
getInitialState () {
return {}
2015-12-15 17:15:12 +01:00
},
2015-12-22 14:49:29 +01:00
componentDidMount () {
this.checkForUpdates()
2015-12-15 17:15:12 +01:00
},
2015-12-22 14:49:29 +01:00
checkForUpdates () {
2015-12-15 17:15:12 +01:00
var v = window.location.pathname
var gateway = /^\/ipns\/(?:Qm[1-9A-HJ-NP-Za-km-z]{44}|[^.]+\.[^.]+)/.test(
window.location.pathname
) || /^\/ipfs\/Qm[1-9A-HJ-NP-Za-km-z]{44}/.test(
window.location.pathname
);
2015-12-23 09:53:18 +01:00
if (v !== '/ipns/boards.ydns.eu/' || !gateway) {
2015-12-22 14:49:29 +01:00
this.setState({ update: true })
2015-12-15 17:15:12 +01:00
}
},
render () {
2015-12-22 14:49:29 +01:00
if (this.state.update) {
return <Link className="nounderline" to='/version' >
<Icon name="history" className="fa-2x light" />
</Link>
} else return <div></div>
2015-12-15 17:15:12 +01:00
}
})
module.exports = function (boardsAPI) {
return React.createClass({
getInitialState: function () {
2015-12-15 17:15:12 +01:00
return { loading: true }
},
componentDidMount () {
boardsAPI.use(boards => {
2015-12-15 17:15:12 +01:00
if (boards.isInit) this.setState({ api: boards, userid: boards.getMyID() })
2015-12-19 17:43:55 +01:00
boards.getEventEmitter().on('init', (err, limited) => {
if (!this.isMounted()) return
if (err) {
2015-12-19 17:43:55 +01:00
this.setState({ loading: false, api: false, limited })
} else {
2015-12-15 17:15:12 +01:00
this.setState({ api: boards, userid: boards.getMyID(), limited })
}
})
})
},
extraButtons: function () {
if (this.state.api) {
return <span>
<Link className="nounderline" to={'/@' + this.state.userid}><Icon name="user" className="fa-2x light"/></Link>
<Link className="nounderline" to="/users"><Icon name="globe" className="fa-2x light"/></Link>
</span>
} else if (this.state.loading) {
2015-12-22 14:00:48 +01:00
return <Link className="nounderline" to="/status"><Icon name="refresh" className="fa-2x fa-spin light"/></Link>
2015-12-19 17:43:55 +01:00
} else if (this.state.limited) {
return <Link className="nounderline" to="/status"><Icon name="exclamation-triangle" className="fa-2x light"/></Link>
} else {
2015-12-19 13:52:38 +01:00
return <Link className="nounderline" to="/status"><Icon name="ban" className="fa-2x light"/></Link>
}
},
render: function () {
return (
<div className="navbar">
<div className="container">
2015-12-15 17:15:12 +01:00
<h4><Link to="/"><Icon name="comments" className="light"/> Boards</Link></h4>
<div className="u-pull-right iconbar">
2015-12-22 14:49:29 +01:00
<Updater/>
{this.extraButtons()}
<Link className="nounderline" to="/settings"><Icon name="cog" className="fa-2x light"/></Link>
<a className="nounderline" href="https://github.com/fazo96/ipfs-boards"><Icon name="github" className="fa-2x light"/></a>
</div>
</div>
</div>)
}
})
}