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

96 lines
3.9 KiB
React
Raw Normal View History

var React = require('react')
var Link = require('react-router').Link
var Icon = require('icon.jsx')
module.exports = React.createClass({
2015-12-19 13:52:38 +01:00
getInitialState () {
2015-12-12 17:51:03 +01:00
return {}
},
2015-12-19 13:52:38 +01:00
componentWillUnmount () {
if (this.timer) clearTimeout(this.timer)
},
componentWillReceiveProps (props) {
this.init(props)
},
2015-12-19 13:52:38 +01:00
componentDidMount () {
this.init(this.props)
2015-12-12 17:51:03 +01:00
},
2015-12-19 13:52:38 +01:00
init (props) {
var boards = props.api
if (this.timer) clearTimeout(this.timer)
if (boards) {
2015-12-19 13:52:38 +01:00
boards.getEventEmitter().on('init', (err, limited) => {
if (!this.isMounted()) return
if (err) {
this.setState({ error: true, limited })
2015-12-12 17:51:03 +01:00
} else {
2015-12-19 13:52:38 +01:00
this.setState({ connected: true })
2015-12-12 17:51:03 +01:00
}
2015-12-19 13:52:38 +01:00
})
if (boards.isInit) {
this.setState({ connected: true })
} else if (boards.limited) {
this.setState({ error: true, limited: true })
} else this.startTimer()
2015-12-12 17:21:58 +01:00
} else this.startTimer()
},
2015-12-19 13:52:38 +01:00
startTimer () {
console.log('start timer')
2015-12-15 17:20:57 +01:00
this.timer = setTimeout(_ => {
2015-12-19 13:52:38 +01:00
console.log('Connection to go-ipfs has timed out (probably due to CORS)')
if (this.isMounted() && !this.state.connected && !this.state.limited) {
2015-12-12 17:51:03 +01:00
this.setState({ long: true })
2015-12-19 13:52:38 +01:00
this.init(this.props)
2015-12-12 17:51:03 +01:00
}
2015-12-12 17:21:58 +01:00
}, 5000)
},
2015-12-19 13:52:38 +01:00
getContent () {
if (this.state.limited) {
return <div>
<h1><Icon name="ban"/> You're running in limited mode</h1>
<h4 className="light">Sorry, but at the moment an external application is needed to fully take advantage of the app</h4>
<p>Only a few features are available in limited mode.</p>
<h5>Why am I running in limited mode?</h5>
</div>
} else {
return <div>
<h1><Icon name="ban"/> Connection to IPFS not available</h1>
<h4 className="light">Sorry, but at the moment an external application is needed to try the Prototype</h4>
<p><b>Tip:</b> you can also run in limited mode by loading the app from an IPFS Gateway.</p>
</div>
}
},
render () {
var opt = require('options.jsx').get()
if (this.state.error || this.state.long) {
return (
2015-12-19 13:52:38 +01:00
<div>
{this.getContent()}
<p>You don't have an IPFS node running at <code>{opt.addr}:{opt.port}</code> or it is not reachable.
The IPFS Boards prototype requires a full IPFS node. Please start one by following the
<a href="https://github.com/ipfs/go-ipfs"><code>go-ipfs</code> documentation.</a></p>
<h5>Do you have a running node but the app won't work?</h5>
<p>It's probably one of these issues:</p>
<ul>
<li>Your node is not located at <code>{opt.addr}:{opt.port}</code>. Go to the <Link to="/settings">Settings Page</Link> to configure the connection.</li>
<li>You edited your settings and saved them but didn't reload the page</li>
<li>Your IPFS node doesn't allow requests from the domain you're running the app from (CORS issue). See <a href="https://github.com/fazo96/ipfs-board/blob/master/ipfs_daemon_set_cors.sh">here</a> for the fix.</li>
<li>You're downloading the app via `https`: at the moment, connecting to IPFS only works if you donwload the app via plain HTTP. If you're using `ipfs.io` please consider accessing the app via a local gateway like `localhost:8080`</li>
<li>Some other networking or browser security issue is preventing the App from talking to your node.</li>
</ul>
<p>Still can't fix it? <a href="https://github.com/fazo96/ipfs-board/issues">File a issue on GitHub</a>, we'll be happy to help!</p>
</div>
) } else if (this.state.connected) {
return <div class="text-center">
<h1><Icon name="check" /></h1>
<h5 class="light">You're connected!</h5>
</div>
} else {
return <div className="center-block text-center">
<Icon name="refresh" className="fa-3x center-block light fa-spin" />
<h4>Connecting to IPFS</h4>
</div>
}
}
})