From 67e34309f67e53a99016314406288bfe86787a08 Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Tue, 24 Nov 2015 21:41:27 +0100 Subject: [PATCH] implemented nested comments and fix #43 --- lib/boards-api.js | 30 ++++++++++++++++++++++-------- webapp/components/comment.jsx | 2 ++ webapp/components/comments.jsx | 6 ++++-- webapp/components/profile.jsx | 2 +- webapp/style.css | 7 +++++++ 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/lib/boards-api.js b/lib/boards-api.js index 5c7637f..48b88ec 100644 --- a/lib/boards-api.js +++ b/lib/boards-api.js @@ -215,6 +215,12 @@ BoardsAPI.prototype.getProfile = function(userID,done){ } BoardsAPI.prototype.getBoardSettings = function(userID,board){ + if(!userID){ + return console.log('Invalid USERID',userID) + } + if(!board){ + return console.log('Invalid BOARD',board) + } this.resolveIPNS(userID,(r,e) => { if(e){ this.ee.emit('error',e) @@ -377,19 +383,25 @@ BoardsAPI.prototype.downloadComment = function(hash,adminID,board,done){ } BoardsAPI.prototype.getCommentsFor = function(parent,board,adminID){ + if(!parent || !board || !adminID){ + return console.log('malformed arguments:',parent,board,adminID) + } this.ee.on('approved comments for '+board+'@'+adminID,ret => { ret.forEach(item => this.downloadComment(item.hash,adminID,board)) }) // get the admin's comments this.getUserCommentList(parent,adminID,(err,res) => { - if(err){ - console.log(err) - } else res.forEach(item => this.downloadComment(item.hash,adminID,board)) + if(!err){ + res.forEach(item => this.downloadComment(item.hash,adminID,board)) + } }) this.getAllowedContentProducers(adminID,board,{ comments: true }) } BoardsAPI.prototype.getUserCommentList = function(parent,user,done){ + if(!parent || !user){ + return console.log('Malformed arguments:',parent,user) + } this.resolveIPNS(user,(url,err) => { if(err){ this.ee.emit('error',err) @@ -399,11 +411,13 @@ BoardsAPI.prototype.getUserCommentList = function(parent,user,done){ this.ee.emit('error',e) done(e) } else if(r && !r.split){ - console.log('Found',r.Objects[0].Links.length,'comments for',parent,'at',user) - var l = r.Objects[0].Links.map(i => { - return { date: i.Name, hash: i.Hash } - }) - done(null,l) + if(r.Objects && r.Objects[0]){ // If this is not true, then there are no comments + console.log('Found',r.Objects[0].Links.length,'comments for',parent,'at',user) + var l = r.Objects[0].Links.map(i => { + return { date: i.Name, hash: i.Hash } + }) + done(null,l) + } } }) return true // remove myself from listeners diff --git a/webapp/components/comment.jsx b/webapp/components/comment.jsx index 5134dcd..b999ed9 100644 --- a/webapp/components/comment.jsx +++ b/webapp/components/comment.jsx @@ -16,12 +16,14 @@ module.exports = function(boardsAPI){ }, render: function(){ if(this.props.comment){ + var Comments = this.props.comment.comments || require('comments.jsx')(boardsAPI) return

+
} else { return

Invalid Comment
diff --git a/webapp/components/comments.jsx b/webapp/components/comments.jsx index b8e8635..f898ad6 100644 --- a/webapp/components/comments.jsx +++ b/webapp/components/comments.jsx @@ -21,10 +21,12 @@ module.exports = function(boardsAPI){ }) }, getComments: function(){ - return this.state.comments.map(cmnt => () ) + if(this.state.comments.length > 0) + return this.state.comments.map(cmnt => () ) + else return
}, render: function(){ - return
{this.getComments()}
+ return
{this.getComments()}
} }) } diff --git a/webapp/components/profile.jsx b/webapp/components/profile.jsx index 36ee9df..c06efd3 100644 --- a/webapp/components/profile.jsx +++ b/webapp/components/profile.jsx @@ -71,7 +71,7 @@ module.exports = function(boardsAPI){

{this.state.name}


-
@{uid}
+
@{uid}
{this.state.boards.map(n => { return
# {n.name} diff --git a/webapp/style.css b/webapp/style.css index 271f481..3f45bef 100644 --- a/webapp/style.css +++ b/webapp/style.css @@ -58,6 +58,10 @@ a:hover { color: #707070 } +.breaker { + word-break: break-all; +} + .app { padding-top: 9rem } @@ -107,6 +111,9 @@ a:hover { margin-right: 1rem; } +.shifted { + margin-left: 2rem; +} .navbar { border-bottom: 1px solid #eee;