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 ipfs = require('ipfs-api')('localhost',5001)
var BoardsAPI = require('../lib/boards-api.js')
var boards = new BoardsAPI(ipfs)
var Container = React.createClass({
render: function(){
return (
{this.props.children}
)
}
})
var App = React.createClass({
render: function(){
return ( {this.props.children}
)
}
})
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 Navbar = React.createClass({
render: function(){
return (
)
}
})
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 })
}
})
ee.on('boards',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 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',(post,hash) => {
if(!this.isMounted()) return true
this.setState({ posts: this.state.posts.concat(post) })
})
},
render: function(){
return (
{this.state.posts.map(post => {
return (
)
})}
)
}
})
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}
)
}
})
var Board = React.createClass({
getInitialState: function(){
return { name: '# '+this.props.params.boardname }
},
componentDidMount: function(){
boards.getBoardSettings(this.props.params.userid,this.props.params.boardname, (err,res) => {
if(!this.isMounted()) return true
if(err) {
console.log('Huh? Invalid board settings?',err)
} else {
console.log('Found name:',res.fullname)
this.setState({ name: '# '+res.fullname.trim() })
}
})
},
render: function(){
return ()
}
})
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!
)
}
})
boards.init(err => {
if(err){
console.log('FATAL: IPFS NODE NOT AVAILABLE')
ReactDOM.render( , document.getElementById('root'))
} else {
ReactDOM.render(
, document.getElementById('root')
)
}
})