mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-01-25 14:54:19 +01:00
settings page implemented
This commit is contained in:
parent
31e3e0313a
commit
f132d5ae43
@ -6,9 +6,15 @@ var IndexRoute = require('react-router').IndexRoute
|
|||||||
var Link = require('react-router').Link
|
var Link = require('react-router').Link
|
||||||
|
|
||||||
var MarkdownLib = require('react-markdown')
|
var MarkdownLib = require('react-markdown')
|
||||||
var ipfs = require('ipfs-api')('localhost',5001)
|
|
||||||
var BoardsAPI = require('../lib/boards-api.js')
|
var BoardsAPI = require('../lib/boards-api.js')
|
||||||
|
|
||||||
|
var opt, s = localStorage.getItem('ipfs-boards-settings')
|
||||||
|
try {
|
||||||
|
opt = JSON.parse(s)
|
||||||
|
} catch(e){
|
||||||
|
opt = { addr: 'localhost', port: 5001 }
|
||||||
|
}
|
||||||
|
var ipfs = require('ipfs-api')(opt.addr || 'localhost',opt.port || 5001)
|
||||||
var boards = new BoardsAPI(ipfs)
|
var boards = new BoardsAPI(ipfs)
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
@ -130,15 +136,19 @@ var Homepage = React.createClass({
|
|||||||
var GetIPFS = React.createClass({
|
var GetIPFS = React.createClass({
|
||||||
render: function(){
|
render: function(){
|
||||||
return (
|
return (
|
||||||
<div className="text-center">
|
<div className="">
|
||||||
<h1>Missing IPFS Node</h1>
|
<h1><Icon name="ban"/> Missing IPFS Node</h1>
|
||||||
<p>You don't have an IPFS node running at <code>localhost:5001</code>
|
<p>You don't have an IPFS node running at <code>{opt.addr}:{opt.port}</code> or it is not reachable</p>
|
||||||
or it is not reachable</p>
|
|
||||||
<p>The IPFS Boards prototype requires a full IPFS node running at localhost.
|
<p>The IPFS Boards prototype requires a full IPFS node running at localhost.
|
||||||
Please start one by following the
|
Please start one by following the
|
||||||
<a href="https://github.com/ipfs/go-ipfs"><code>go-ipfs</code> documentation.</a></p>
|
<a href="https://github.com/ipfs/go-ipfs"><code>go-ipfs</code> documentation.</a></p>
|
||||||
<p>If you have a running node but still this doesn't work, it's probably a CORS issue</p>
|
<h5>Do you have a running node but the app won't work?</h5>
|
||||||
<p>You can find out how to fix CORS issues related to this app <a href="https://github.com/fazo96/ipfs-board/blob/master/ipfs_daemon_set_cors.sh">here</a>.</p>
|
<p>It's probably one of these issues:</p>
|
||||||
|
<ul>
|
||||||
|
<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>Your IPFS node is not listening for API requests at <code>{opt.addr}:{opt.port}</code>. Go to the <Link to="/settings">Settings page</Link>, provide the correct address for the node, then save and reload the page.</li>
|
||||||
|
<li>Some other networking 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>
|
<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>
|
</div>
|
||||||
)
|
)
|
||||||
@ -234,32 +244,51 @@ var Users = React.createClass({
|
|||||||
})
|
})
|
||||||
|
|
||||||
var Settings = React.createClass({
|
var Settings = React.createClass({
|
||||||
|
getDefaults: function(){
|
||||||
|
return { addr: 'localhost', port: 5001 }
|
||||||
|
},
|
||||||
getInitialState: function(){
|
getInitialState: function(){
|
||||||
// get from localstorage
|
var s = localStorage.getItem('ipfs-boards-settings')
|
||||||
return { addr: 'localhost', port: '5001' }
|
var obj = this.getDefaults()
|
||||||
|
try {
|
||||||
|
obj = JSON.parse(s)
|
||||||
|
} catch(e){
|
||||||
|
localStorage.removeItem('ipfs-boards-settings')
|
||||||
|
}
|
||||||
|
return obj || this.getDefaults()
|
||||||
},
|
},
|
||||||
save: function(){
|
save: function(){
|
||||||
// write to localstorage
|
if(isNaN(this.state.port) || parseInt(this.state.port) > 65535 || parseInt(this.state.port) < 1){
|
||||||
|
alert('Port number invalid')
|
||||||
|
} else {
|
||||||
|
localStorage.setItem('ipfs-boards-settings',JSON.stringify({
|
||||||
|
addr: this.state.addr,
|
||||||
|
port: parseInt(this.state.port)
|
||||||
|
}))
|
||||||
|
alert('Saved')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
setDefaults: function(){
|
setDefaults: function(){
|
||||||
this.setState({ addr: 'localhost', port: '5001' })
|
this.setState(this.getDefaults())
|
||||||
},
|
},
|
||||||
onChange: function(event){
|
onChange: function(event){
|
||||||
console.log(event.target.id)
|
if(event.target.id === 'nodeAddress'){
|
||||||
//this.setState({})
|
this.setState({ addr: event.target.value })
|
||||||
|
} else {
|
||||||
|
this.setState({ port: event.target.value })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
render: function(){
|
render: function(){
|
||||||
return (
|
return (
|
||||||
<div className="settings">
|
<div className="settings">
|
||||||
<h2><Icon name="cog"/> Settings</h2>
|
<h2><Icon name="cog"/> Settings</h2>
|
||||||
<h4>Note that this page doesn't work yet.</h4>
|
<h5>This page is still a little rough, but it works. Reload the page after saving to apply changes.</h5>
|
||||||
<p>Use this page to customize the application's behavior. For now, you can change how it connects to IPFS.</p>
|
<p>Use this page to customize the application's behavior. For now, you can change how it connects to IPFS.</p>
|
||||||
<p>All settings are saved in your browser.</p>
|
<p>All settings are saved in your browser.</p>
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="six columns">
|
<div className="six columns">
|
||||||
<label for="nodeAddress">IPFS Node</label>
|
<label for="nodeAddress">IPFS Node</label>
|
||||||
<input className="u-full-width" type="text" id="nodeAddess" value={this.state.addr} onChange={this.onChange} placeholder="localhost" />
|
<input className="u-full-width" type="text" id="nodeAddress" value={this.state.addr} onChange={this.onChange} placeholder="localhost" />
|
||||||
</div>
|
</div>
|
||||||
<div className="six columns">
|
<div className="six columns">
|
||||||
<label for="nodePort">API Port</label>
|
<label for="nodePort">API Port</label>
|
||||||
@ -280,7 +309,14 @@ var Settings = React.createClass({
|
|||||||
boards.init(err => {
|
boards.init(err => {
|
||||||
if(err){
|
if(err){
|
||||||
console.log('FATAL: IPFS NODE NOT AVAILABLE')
|
console.log('FATAL: IPFS NODE NOT AVAILABLE')
|
||||||
ReactDOM.render(<App><GetIPFS/></App>, document.getElementById('root'))
|
ReactDOM.render(
|
||||||
|
<Router>
|
||||||
|
<Route path="/" component={App}>
|
||||||
|
<IndexRoute component={GetIPFS} />
|
||||||
|
<Route path="/settings" component={Settings} />
|
||||||
|
</Route>
|
||||||
|
</Router>
|
||||||
|
, document.getElementById('root'))
|
||||||
} else {
|
} else {
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<Router>
|
<Router>
|
||||||
|
Loading…
Reference in New Issue
Block a user