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)
boards.init(_ => {
console.log('Boards init complete')
})
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(err){
console.log(err)
this.setState({
name: '?',
error: 'Invalid profile'
})
} else {
console.log(res)
this.setState({ name: res.name })
}
})
ee.on('boards',l => {
console.log('Arrived boards',l)
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(){
var ee = boards.getPostsInBoard(this.props.admin,this.props.board)
ee.on('post',(post) => {
var posts = this.state.posts
posts.push(post)
this.setState({ posts })
})
},
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(!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(err) {
console.log('Huh? Invalid board settings?',err)
} else {
console.log('Found name:',res.fullname)
this.setState({ name: '# '+res.fullname.trim() })
}
})
},
render: function(){
return ()
}
})
ReactDOM.render(
, document.getElementById('root')
)