diff --git a/webapp/app.jsx b/webapp/app.jsx index 680f149..bcee0b8 100644 --- a/webapp/app.jsx +++ b/webapp/app.jsx @@ -6,9 +6,15 @@ var IndexRoute = require('react-router').IndexRoute var Link = require('react-router').Link var MarkdownLib = require('react-markdown') -var ipfs = require('ipfs-api')('localhost',5001) 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) // Components @@ -130,15 +136,19 @@ var Homepage = React.createClass({ var GetIPFS = React.createClass({ render: function(){ return ( -
-

Missing IPFS Node

-

You don't have an IPFS node running at localhost:5001 - or it is not reachable

+
+

Missing IPFS Node

+

You don't have an IPFS node running at {opt.addr}:{opt.port} or it is not reachable

The IPFS Boards prototype requires a full IPFS node running at localhost. Please start one by following the go-ipfs documentation.

-

If you have a running node but still this doesn't work, it's probably a CORS issue

-

You can find out how to fix CORS issues related to this app here.

+
Do you have a running node but the app won't work?
+

It's probably one of these issues:

+

Still can't fix it? File a issue on GitHub, we'll be happy to help!

) @@ -234,32 +244,51 @@ var Users = React.createClass({ }) var Settings = React.createClass({ + getDefaults: function(){ + return { addr: 'localhost', port: 5001 } + }, getInitialState: function(){ - // get from localstorage - return { addr: 'localhost', port: '5001' } + var s = localStorage.getItem('ipfs-boards-settings') + var obj = this.getDefaults() + try { + obj = JSON.parse(s) + } catch(e){ + localStorage.removeItem('ipfs-boards-settings') + } + return obj || this.getDefaults() }, 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(){ - this.setState({ addr: 'localhost', port: '5001' }) + this.setState(this.getDefaults()) }, onChange: function(event){ - console.log(event.target.id) - //this.setState({}) + if(event.target.id === 'nodeAddress'){ + this.setState({ addr: event.target.value }) + } else { + this.setState({ port: event.target.value }) + } }, render: function(){ return (

Settings

-

Note that this page doesn't work yet.

+
This page is still a little rough, but it works. Reload the page after saving to apply changes.

Use this page to customize the application's behavior. For now, you can change how it connects to IPFS.

All settings are saved in your browser.

- +
@@ -280,7 +309,14 @@ var Settings = React.createClass({ boards.init(err => { if(err){ console.log('FATAL: IPFS NODE NOT AVAILABLE') - ReactDOM.render(, document.getElementById('root')) + ReactDOM.render( + + + + + + + , document.getElementById('root')) } else { ReactDOM.render(