diff --git a/webapp/components/comment.jsx b/webapp/components/comment.jsx index f4dee22..d6db7a1 100644 --- a/webapp/components/comment.jsx +++ b/webapp/components/comment.jsx @@ -3,48 +3,79 @@ var Markdown = require('markdown.jsx') var Icon = require('icon.jsx') var Clock = require('clock.jsx') var Link = require('react-router').Link +var UserID = require('userID.jsx') -module.exports = function(boardsAPI){ - var UserID = require('userID.jsx')(boardsAPI) - return React.createClass({ - getInitialState: function(){ - return { moment: false } - }, - componentDidMount: function(){ - require.ensure(['moment'],_ => { - if(this.isMounted()) this.setState({ moment: require('moment') }) - }) - }, - getPermalink: function(){ - if(this.props.adminID && this.props.board && this.props.post && this.props.comment.hash){ - return
- Permalink -
- } - }, - getParentlink: function(){ - if(this.props.showParent && this.props.comment.parent && this.props.comment.parent !== this.props.post){ - return
- Parent -
- } - }, - render: function(){ - if(this.props.comment){ - var Comments = this.props.comment.comments || require('comments.jsx')(boardsAPI) - return

-
- - - {this.getPermalink()} - {this.getParentlink()} -
- - -
- } else { - return

Invalid Comment
- } +var Comment = React.createClass({ + getInitialState: function(){ + return { moment: false } + }, + componentDidMount: function(){ + require.ensure(['moment'],_ => { + if(this.isMounted()) this.setState({ moment: require('moment') }) + }) + }, + getPermalink: function(){ + if(this.props.adminID && this.props.board && this.props.post && this.props.comment.hash){ + return
+ Permalink +
} - }) -} + }, + getParentlink: function(){ + if(this.props.showParent && this.props.comment.parent && this.props.comment.parent !== this.props.post){ + return
+ Parent +
+ } + }, + getComments: function(){ + return + }, + render: function(){ + if(this.props.comment){ + return

+
+ + + {this.getPermalink()} + {this.getParentlink()} +
+ +
+ } else { + return

Invalid Comment
+ } + } +}) + +var Comments = React.createClass({ + getInitialState: function(){ + return { comments: [] } + }, + componentDidMount: function(){ + var boards = this.props.api + if(boards){ + boards.getEventEmitter().on('comment for '+this.props.parent,cmnt => { + if(this.isMounted()) this.setState({ comments: this.state.comments.concat(cmnt) }) + }) + if(boards.isInit && this.isMounted()){ + boards.getCommentsFor(this.props.parent,this.props.board,this.props.adminID) + } + boards.getEventEmitter().on('init', err => { + if(!err && this.isMounted()) + boards.getCommentsFor(this.props.parent,this.props.board,this.props.adminID) + }) + } + }, + getComments: function(){ + if(this.state.comments.length > 0){ + return this.state.comments.map(cmnt => () ) + } + else return
+ }, + render: function(){ + return
{this.getComments()}
+ } +}) + +module.exports = { Comment, Comments } diff --git a/webapp/components/comments.jsx b/webapp/components/comments.jsx deleted file mode 100644 index b2ebc24..0000000 --- a/webapp/components/comments.jsx +++ /dev/null @@ -1,32 +0,0 @@ -var React = require('react') - -module.exports = function(boardsAPI){ - var Comment = require('comment.jsx')(boardsAPI) - return React.createClass({ - getInitialState: function(){ - return { comments: [] } - }, - componentDidMount: function(){ - boardsAPI.use(boards => { - boards.getEventEmitter().on('comment for '+this.props.parent,cmnt => { - if(this.isMounted()) this.setState({ comments: this.state.comments.concat(cmnt) }) - }) - if(boards.isInit && this.isMounted()){ - boards.getCommentsFor(this.props.parent,this.props.board,this.props.adminID) - } - boards.getEventEmitter().on('init', err => { - if(!err && this.isMounted()) - boards.getCommentsFor(this.props.parent,this.props.board,this.props.adminID) - }) - }) - }, - getComments: function(){ - if(this.state.comments.length > 0) - return this.state.comments.map(cmnt => () ) - else return
- }, - render: function(){ - return
{this.getComments()}
- } - }) -} diff --git a/webapp/components/post.jsx b/webapp/components/post.jsx index c34deac..58849c7 100644 --- a/webapp/components/post.jsx +++ b/webapp/components/post.jsx @@ -4,8 +4,8 @@ var Icon = require('icon.jsx') var Link = require('react-router').Link var Clock = require('clock.jsx') -module.exports = function(boardsAPI){ - var UserID = require('userID.jsx')(boardsAPI) +module.exports = function(){ + var UserID = require('userID.jsx')() return React.createClass({ getInitialState: function(){ return { moment: false } @@ -32,7 +32,7 @@ module.exports = function(boardsAPI){
{this.props.post.title}


- + View
diff --git a/webapp/components/postlist.jsx b/webapp/components/postlist.jsx index bc5b0fc..31fd63f 100644 --- a/webapp/components/postlist.jsx +++ b/webapp/components/postlist.jsx @@ -2,8 +2,8 @@ var React = require('react') var sortedIndex = require('lodash.sortedindex') var Icon = require('icon.jsx') -module.exports = function(boardsAPI){ - var Post = require('post.jsx')(boardsAPI) +module.exports = function(){ + var Post = require('post.jsx')() return React.createClass({ getInitialState: function(){ return { posts: [], api: false } @@ -30,17 +30,18 @@ module.exports = function(boardsAPI){ }) }, componentDidMount: function(){ - boardsAPI.use(boards => { + var boards = this.props.api + if(boards){ if(boards.isInit) this.init(boards) else boards.getEventEmitter().on('init',err => { if(!err && this.isMounted()) this.init(boards) }) - }) + } }, getPosts: function(){ if(this.state.posts.length > 0 || this.state.api){ return this.state.posts.map(post => { - return + return }) } else return
diff --git a/webapp/components/userID.jsx b/webapp/components/userID.jsx index d37e53c..fc84d78 100644 --- a/webapp/components/userID.jsx +++ b/webapp/components/userID.jsx @@ -2,21 +2,22 @@ var React = require('react') var Icon = require('icon.jsx') var Link = require('react-router').Link -module.exports = function(boardsAPI){ +module.exports = function(){ return React.createClass({ getInitialState: function(){ return { } }, componentDidMount: function(){ - boardsAPI.use(boards => { + var boards = this.props.api + if(boards){ if(boards.isInit){ this.getProfile(boards) } boards.getEventEmitter().on('init',err => { - if(!err) this.getProfile(boards) + if(!err && this.isMounted()) this.getProfile(boards) else console.log('ERR INIT',err) }) - }) + } }, getProfile: function(boards){ if(this.props.id === undefined) return diff --git a/webapp/pages/board.jsx b/webapp/pages/board.jsx index 6a4fa70..0c6f787 100644 --- a/webapp/pages/board.jsx +++ b/webapp/pages/board.jsx @@ -4,9 +4,9 @@ var Link = require('react-router').Link var Icon = require('icon.jsx') module.exports = function(boardsAPI){ - var UserID = require('userID.jsx')(boardsAPI) - var PostList = require('postlist.jsx')(boardsAPI) - var GetIPFS = require('getipfs.jsx')(boardsAPI) + var UserID = require('userID.jsx')() + var PostList = require('postlist.jsx')() + var GetIPFS = require('getipfs.jsx')() return React.createClass({ getInitialState: function(){ return { name: this.props.params.boardname, api: false } @@ -24,7 +24,6 @@ module.exports = function(boardsAPI){ var ee = boards.getEventEmitter() ee.on('init',err => { if(!err && this.isMounted()){ - this.setState({ api: true }) this.init(boards) } }) @@ -37,7 +36,6 @@ module.exports = function(boardsAPI){ this.setState({ description: 'All the messages posted in __#'+this.props.params.boardname+'__' }) } if(boards.isInit || this.state.api){ - this.setState({api: true}) this.init(boards) } }) @@ -46,7 +44,7 @@ module.exports = function(boardsAPI){ if(!this.state.init){ if(this.props.params.userid) boards.getBoardSettings(this.props.params.userid,this.props.params.boardname) - this.setState({ init: true }) + this.setState({ init: true, api: true, boards: boards }) } }, render: function(){ @@ -54,11 +52,11 @@ module.exports = function(boardsAPI){ return (

{this.state.name}

- {this.props.params.userid?
:

} + {this.props.params.userid?
:

}
- +
) - } else return + } else return } }) } diff --git a/webapp/pages/commentpage.jsx b/webapp/pages/commentpage.jsx index e7b29b5..347a5d1 100644 --- a/webapp/pages/commentpage.jsx +++ b/webapp/pages/commentpage.jsx @@ -3,10 +3,10 @@ var Link = require('react-router').Link var Icon = require('icon.jsx') module.exports = function(boardsAPI){ - var UserID = require('userID.jsx')(boardsAPI) - var GetIPFS = require('getipfs.jsx')(boardsAPI) - var Post = require('post.jsx')(boardsAPI) - var Comment = require('comment.jsx')(boardsAPI) + var UserID = require('userID.jsx')() + var GetIPFS = require('getipfs.jsx')() + var Post = require('post.jsx')() + var Comment = require('comment.jsx').Comment return React.createClass({ getInitialState: function(){ @@ -27,7 +27,7 @@ module.exports = function(boardsAPI){ }, init: function(boards){ if(this.state.init) return - this.setState({ api: true }) + this.setState({ api: true, boards: boards }) boards.downloadComment(this.props.params.commenthash,this.props.params.userid,this.props.params.boardname,(err,comment) => { if(err){ this.setState({ comment: { title: 'Error', text: err.Message || err.Error }}) @@ -39,14 +39,14 @@ module.exports = function(boardsAPI){ getContext: function(){ if(this.props.params.userid){ if(this.props.params.boardname) - return
Comment by in #{this.props.params.boardname} to {this.props.params.posthash}
+ return
Comment by in #{this.props.params.boardname} to {this.props.params.posthash}
else - return
Comment by
+ return
Comment by
} else return
You are viewing a single comment
}, showComment: function(){ if(this.state.comment){ - return + return } else { return
@@ -62,7 +62,7 @@ module.exports = function(boardsAPI){
{this.showComment()}
- else return + else return } }) } diff --git a/webapp/pages/getipfs.jsx b/webapp/pages/getipfs.jsx index d7a4246..8993bcc 100644 --- a/webapp/pages/getipfs.jsx +++ b/webapp/pages/getipfs.jsx @@ -2,13 +2,14 @@ var React = require('react') var Link = require('react-router').Link var Icon = require('icon.jsx') -module.exports = function(boardsAPI){ +module.exports = function(){ return React.createClass({ getInitialState: function(){ return { connected: false, error: false, long: false } }, componentDidMount: function(){ - boardsAPI.use(boards => { + var boards = this.props.api + if(boards){ if(!this.isMounted()) return if(boards.isInit){ this.setState({ connected: true }) @@ -25,7 +26,7 @@ module.exports = function(boardsAPI){ } }) } - }) + } }, render: function(){ var opt = require('options.jsx').get() diff --git a/webapp/pages/postpage.jsx b/webapp/pages/postpage.jsx index 411c571..8575417 100644 --- a/webapp/pages/postpage.jsx +++ b/webapp/pages/postpage.jsx @@ -2,10 +2,10 @@ var React = require('react') var Link = require('react-router').Link module.exports = function(boardsAPI){ - var UserID = require('userID.jsx')(boardsAPI) - var GetIPFS = require('getipfs.jsx')(boardsAPI) - var Post = require('post.jsx')(boardsAPI) - var Comments = require('comments.jsx')(boardsAPI) + var UserID = require('userID.jsx')() + var GetIPFS = require('getipfs.jsx')() + var Post = require('post.jsx')() + var Comments = require('comment.jsx').Comments return React.createClass({ getInitialState: function(){ @@ -26,7 +26,7 @@ module.exports = function(boardsAPI){ }, init: function(boards){ if(this.state.init) return - this.setState({ api: true }) + this.setState({ api: true, boards: boards }) boards.downloadPost(this.props.params.posthash,this.props.params.userid,this.props.params.boardname,this.props.params.userid,(err,post) => { if(err){ this.setState({ post: { title: 'Error', text: err.Message || err.Error }}) @@ -38,9 +38,9 @@ module.exports = function(boardsAPI){ getContext: function(){ if(this.props.params.userid){ if(this.props.params.boardname) - return
Posted by in #{this.props.params.boardname}
+ return
Posted by in #{this.props.params.boardname}
else - return
Posted by
+ return
Posted by
} else return
You are viewing a single post
}, render: function(){ @@ -49,10 +49,10 @@ module.exports = function(boardsAPI){
{this.getContext()}
- - + + - else return + else return } }) } diff --git a/webapp/pages/profile.jsx b/webapp/pages/profile.jsx index c06efd3..b8084fe 100644 --- a/webapp/pages/profile.jsx +++ b/webapp/pages/profile.jsx @@ -12,13 +12,13 @@ module.exports = function(boardsAPI){ componentDidMount: function(){ boardsAPI.use(boards => { if(boards.isInit){ - this.setState({ api: true, id: boards.id }) + this.setState({ api: boards, id: boards.id }) this.init() } var ee = boards.getEventEmitter() ee.on('init',err => { if(!err && this.isMounted()){ - this.setState({ api: true, id: boards.id }) + this.setState({ api: boards, id: boards.id }) this.init() } }) @@ -78,7 +78,7 @@ module.exports = function(boardsAPI){ })} ) - } else return + } else return } }) } diff --git a/webapp/pages/users.jsx b/webapp/pages/users.jsx index b8f080c..46bd53e 100644 --- a/webapp/pages/users.jsx +++ b/webapp/pages/users.jsx @@ -2,8 +2,8 @@ var React = require('react') var Icon = require('icon.jsx') module.exports = function(boardsAPI){ - var GetIPFS = require('getipfs.jsx')(boardsAPI) - var UserID = require('userID.jsx')(boardsAPI) + var GetIPFS = require('getipfs.jsx')() + var UserID = require('userID.jsx')() return React.createClass({ getInitialState: function(){ return { users: [], api: false } @@ -13,7 +13,6 @@ module.exports = function(boardsAPI){ boards.init() if(boards.isInit){ if(this.isMounted()){ - this.setState({ api: true }) this.init(boards) } } @@ -21,7 +20,6 @@ module.exports = function(boardsAPI){ ee.on('init', e => { if(!e && this.isMounted()){ this.init(boards) - this.setState({ api: true }) } }) ee.on('user',(id) => { @@ -34,7 +32,7 @@ module.exports = function(boardsAPI){ }, init: function(boards){ if(this.isMounted() && !this.state.init){ - this.setState({ users: boards.getUsers(), init: true }) + this.setState({ users: boards.getUsers(), api: true, init: true, boards: boards }) boards.searchUsers() } }, @@ -45,11 +43,11 @@ module.exports = function(boardsAPI){

Found {this.state.users.length} users

    {this.state.users.map(user => { - return + return })}
- } else return + } else return } }) }