var React = require('react')
var ReactDOM = require('react-dom')
var Router = require('react-router').Router
var Route = require('react-router').Route
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 boards = new BoardsAPI(ipfs)
// Components
var Markdown = React.createClass({
renderIfApplicable: function(){
if(this.props.source)
return
return
...
},
render: function(){
return this.renderIfApplicable()
}
})
var Icon = React.createClass({
class: function(){
return 'fa fa-'+this.props.name+' '+this.props.class
},
render: function(){
return ( )
}
})
var Container = React.createClass({
render: function(){
return ( {this.props.children}
)
}
})
var App = React.createClass({
render: function(){
return ( {this.props.children}
)
}
})
var Navbar = React.createClass({
render: function(){
return (
)
}
})
var PostList = React.createClass({
getInitialState: function(){
return { posts: [] }
},
componentDidMount: function(){
console.log('Initial POSTS',this.state.posts.length)
boards.getPostsInBoard(this.props.admin,this.props.board)
.on('post in '+this.props.board+'@'+this.props.admin,(post,hash) => {
if(!this.isMounted()) return true
this.setState({ posts: this.state.posts.concat(post) })
})
},
render: function(){
return (
{this.state.posts.map(post => {
return (
{post.title}
)
})}
)
}
})
var UserID = React.createClass({
getInitialState: function(){
return { name: '@'+this.props.id }
},
componentDidMount: function(){
boards.getProfile(this.props.id, (err,res) => {
if(!this.isMounted()) return true
if(!err) {
this.setState({ name: res.name.trim() })
}
})
},
render: function(){
return (
{this.state.name}
)
}
})
// Static pages
var Homepage = React.createClass({
render: function(){
return (
Welcome to the IPFS Boards Prototype
Not much is implemented...
You can try Opening my Profile though :)
More information about the project on GitHub
)
}
})
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
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 .
Still can't fix it? File a issue on GitHub , we'll be happy to help!
)
}
})
var NotFound = React.createClass({
render: function(){
return (
Sorry, there's nothing here!
)
}
})
var NotImplemented = React.createClass({
render: function(){
return (
Not yet implemented
Sorry, working on it!
)
}
})
// Dynamic pages
var Profile = React.createClass({
getInitialState: function(){
return { name: '...', boards: [] }
},
componentDidMount: function(){
var ee = boards.getProfile(this.props.params.userid, (err,res) => {
if(!this.isMounted()) return true
if(err){
console.log(err)
this.setState({
name: '?',
error: 'Invalid profile'
})
} else {
console.log(res)
this.setState({ name: res.name, description: res.description })
}
})
ee.on('boards for '+this.props.params.userid,l => {
if(!this.isMounted()) return true
this.setState({ boards: l })
})
},
render: function(){
return (
{this.state.name}
{this.state.error}
@{this.props.params.userid}
{this.state.boards.map(n => {
return
# {n.name}
})}
)
}
})
var Board = React.createClass({
getInitialState: function(){
return { name: this.props.params.boardname }
},
componentDidMount: function(){
var ee = boards.getBoardSettings(this.props.params.userid,this.props.params.boardname)
ee.on('settings for '+this.props.params.boardname+'@'+this.props.params.userid, (res) => {
if(!this.isMounted()) return true
console.log('Found name:',res.fullname)
this.setState({ name: res.fullname.trim(), description: res.description })
})
},
render: function(){
return ()
}
})
var Users = React.createClass({
render: function(){
return
}
})
var Settings = React.createClass({
getInitialState: function(){
// get from localstorage
return { addr: 'localhost', port: '5001' }
},
save: function(){
// write to localstorage
},
setDefaults: function(){
this.setState({ addr: 'localhost', port: '5001' })
},
onChange: function(event){
console.log(event.target.id)
//this.setState({})
},
render: function(){
return (
Settings
Note that this page doesn't work yet.
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.
Save
Defaults
)
}
})
// Start
boards.init(err => {
if(err){
console.log('FATAL: IPFS NODE NOT AVAILABLE')
ReactDOM.render( , document.getElementById('root'))
} else {
ReactDOM.render(
, document.getElementById('root')
)
}
})