2015-11-14 01:34:03 +01:00
var React = require ( 'react' )
var ReactDOM = require ( 'react-dom' )
2015-11-14 13:12:48 +01:00
var Router = require ( 'react-router' ) . Router
var Route = require ( 'react-router' ) . Route
var IndexRoute = require ( 'react-router' ) . IndexRoute
2015-11-18 15:40:29 +01:00
var Redirect = require ( 'react-router' ) . Redirect
2015-11-14 13:12:48 +01:00
var Link = require ( 'react-router' ) . Link
2015-11-20 14:20:06 +01:00
var BoardsAPI = require ( 'boards-api.js' )
// Load CSS
require ( 'normalize.css' )
require ( 'skeleton.css' )
require ( 'style.css' )
2015-11-20 17:24:06 +01:00
require ( 'raleway.css' )
2015-11-20 14:20:06 +01:00
require ( 'font-awesome.min.css' )
2015-11-14 12:06:37 +01:00
2015-11-18 00:37:24 +01:00
var opt , s = localStorage . getItem ( 'ipfs-boards-settings' )
try {
opt = JSON . parse ( s )
} catch ( e ) {
2015-11-18 01:55:31 +01:00
// Do nothing
2015-11-18 00:37:24 +01:00
}
2015-11-18 01:55:31 +01:00
if ( opt === null || opt === undefined ) opt = { addr : 'localhost' , port : 5001 }
2015-11-18 00:37:24 +01:00
var ipfs = require ( 'ipfs-api' ) ( opt . addr || 'localhost' , opt . port || 5001 )
2015-11-14 12:06:37 +01:00
var boards = new BoardsAPI ( ipfs )
2015-11-17 20:32:52 +01:00
// Components
var Container = React . createClass ( {
2015-11-14 12:06:37 +01:00
render : function ( ) {
2015-11-17 20:32:52 +01:00
return ( < div className = "container app" > { this . props . children } < / div > )
}
} )
var App = React . createClass ( {
render : function ( ) {
return ( < div > < Navbar / > < Container > { this . props . children } < / Container > < / div > )
2015-11-14 12:06:37 +01:00
}
} )
var Navbar = React . createClass ( {
render : function ( ) {
return (
< div className = "navbar" >
< div className = "container" >
2015-11-19 17:06:52 +01:00
{ this . props . children || < h4 > < Link to = "/" > < Icon name = "comments" className = "light" / > Boards < / Link > < / h4 > }
< div className = "u-pull-right iconbar" >
< Link className = "nounderline" to = "/@me" > < Icon name = "user" className = "fa-2x light" / > < / Link >
< Link className = "nounderline" to = "/users" > < Icon name = "globe" className = "fa-2x light" / > < / Link >
< 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 >
2015-11-17 20:32:52 +01:00
< / div >
2015-11-14 12:06:37 +01:00
< / div >
< / div > )
}
} )
2015-11-17 20:32:52 +01:00
// Static pages
2015-11-21 16:29:54 +01:00
var Static = React . createClass ( {
html : function ( ) {
return { _ _html : this . props . content }
} ,
render : function ( ) {
if ( this . props . content ) {
return < div className = { this . props . className } dangerouslySetInnerHTML = { this . html ( ) } / >
} else {
return < NotFound / >
}
}
} )
/ * v a r H o m e p a g e = R e a c t . c r e a t e C l a s s ( {
2015-11-14 16:26:03 +01:00
render : function ( ) {
2015-11-17 20:32:52 +01:00
return (
< div >
< h3 > Welcome to the IPFS Boards Prototype < / h3 >
< p > Not much is implemented ... < / p >
< p > You can try < Link to = "@QmXnfA41SXMX3tqFD4kjED7ehyvgTsuAho86TkEoTbZdpw" > Opening my Profile < / Link > though : ) < / p >
< p > More information about the project on < a href = "https://github.com/fazo96/ipfs-board" > GitHub < / a > < / p >
< / div >
)
2015-11-14 15:03:38 +01:00
}
2015-11-21 16:29:54 +01:00
} ) * /
var Homepage = React . createClass ( {
render : function ( ) {
return < Static className = "homepage" content = { require ( 'landing.md' ) } / >
}
2015-11-14 15:03:38 +01:00
} )
2015-11-14 23:33:50 +01:00
var GetIPFS = React . createClass ( {
render : function ( ) {
return (
2015-11-18 00:37:24 +01:00
< div className = "" >
< h1 > < Icon name = "ban" / > Missing IPFS Node < / h1 >
< p > You don ' t have an IPFS node running at < code > { opt . addr } : { opt . port } < / code > or it is not reachable < / p >
2015-11-14 23:33:50 +01:00
< p > The IPFS Boards prototype requires a full IPFS node running at localhost .
Please start one by following the
< a href = "https://github.com/ipfs/go-ipfs" > < code > go - ipfs < / code > documentation . < / a > < / p >
2015-11-18 00:37:24 +01:00
< 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 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 >
2015-11-14 23:33:50 +01:00
< 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 >
)
}
} )
2015-11-17 20:32:52 +01:00
var NotFound = React . createClass ( {
render : function ( ) {
return ( < div className = "text-center" >
< h1 > < Icon name = "ban" / > < / h1 >
< p > Sorry , there ' s nothing here ! < / p >
< / div > )
}
} )
var NotImplemented = React . createClass ( {
render : function ( ) {
return ( < div className = "text-center" >
< h1 > Not yet implemented < / h1 >
2015-11-19 16:56:02 +01:00
< h1 > < Icon name = "cog" className = "fa-spin" / > < / h1 >
2015-11-17 20:32:52 +01:00
< p > Sorry , working on it ! < / p >
< / div > )
}
} )
// Start
2015-11-20 20:21:54 +01:00
var Users = require ( 'users.jsx' ) ( boards )
var Settings = require ( 'settings.jsx' ) ( boards )
var Profile = require ( 'profile.jsx' ) ( boards )
var Board = require ( 'board.jsx' ) ( boards )
var Icon = require ( 'icon.jsx' )
2015-11-14 23:33:50 +01:00
boards . init ( err => {
if ( err ) {
console . log ( 'FATAL: IPFS NODE NOT AVAILABLE' )
2015-11-18 00:37:24 +01:00
ReactDOM . render (
< Router >
< Route path = "/" component = { App } >
2015-11-21 16:29:54 +01:00
< IndexRoute component = { Homepage } / >
2015-11-18 00:37:24 +01:00
< Route path = "/settings" component = { Settings } / >
2015-11-21 16:29:54 +01:00
< Route path = "*" component = { GetIPFS } / >
2015-11-18 00:37:24 +01:00
< / Route >
< / Router >
, document . getElementById ( 'root' ) )
2015-11-14 23:33:50 +01:00
} else {
ReactDOM . render (
< Router >
< Route path = "/" component = { App } >
< IndexRoute component = { Homepage } / >
2015-11-18 15:40:29 +01:00
< Redirect from = "/@me" to = { '/@' + boards . id } / >
2015-11-14 23:33:50 +01:00
< Route path = "/@:userid" >
< IndexRoute component = { Profile } / >
2015-11-17 20:32:52 +01:00
< Route path = ":boardname" component = { Board } / >
2015-11-14 23:33:50 +01:00
< / Route >
2015-11-17 20:32:52 +01:00
< Route path = "/users" component = { Users } / >
< Route path = "/settings" component = { Settings } / >
< Route path = "*" component = { NotFound } / >
2015-11-14 23:33:50 +01:00
< / Route >
< / Router > , document . getElementById ( 'root' )
)
}
} )