1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-10 12:24:20 +01:00

implemented nested comments and fix #43

This commit is contained in:
Enrico Fasoli 2015-11-24 21:41:27 +01:00
parent 39627d8d43
commit 67e34309f6
5 changed files with 36 additions and 11 deletions

View File

@ -215,6 +215,12 @@ BoardsAPI.prototype.getProfile = function(userID,done){
} }
BoardsAPI.prototype.getBoardSettings = function(userID,board){ 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) => { this.resolveIPNS(userID,(r,e) => {
if(e){ if(e){
this.ee.emit('error',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){ 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 => { this.ee.on('approved comments for '+board+'@'+adminID,ret => {
ret.forEach(item => this.downloadComment(item.hash,adminID,board)) ret.forEach(item => this.downloadComment(item.hash,adminID,board))
}) })
// get the admin's comments // get the admin's comments
this.getUserCommentList(parent,adminID,(err,res) => { this.getUserCommentList(parent,adminID,(err,res) => {
if(err){ if(!err){
console.log(err) res.forEach(item => this.downloadComment(item.hash,adminID,board))
} else res.forEach(item => this.downloadComment(item.hash,adminID,board)) }
}) })
this.getAllowedContentProducers(adminID,board,{ comments: true }) this.getAllowedContentProducers(adminID,board,{ comments: true })
} }
BoardsAPI.prototype.getUserCommentList = function(parent,user,done){ BoardsAPI.prototype.getUserCommentList = function(parent,user,done){
if(!parent || !user){
return console.log('Malformed arguments:',parent,user)
}
this.resolveIPNS(user,(url,err) => { this.resolveIPNS(user,(url,err) => {
if(err){ if(err){
this.ee.emit('error',err) this.ee.emit('error',err)
@ -399,11 +411,13 @@ BoardsAPI.prototype.getUserCommentList = function(parent,user,done){
this.ee.emit('error',e) this.ee.emit('error',e)
done(e) done(e)
} else if(r && !r.split){ } else if(r && !r.split){
console.log('Found',r.Objects[0].Links.length,'comments for',parent,'at',user) if(r.Objects && r.Objects[0]){ // If this is not true, then there are no comments
var l = r.Objects[0].Links.map(i => { console.log('Found',r.Objects[0].Links.length,'comments for',parent,'at',user)
return { date: i.Name, hash: i.Hash } var l = r.Objects[0].Links.map(i => {
}) return { date: i.Name, hash: i.Hash }
done(null,l) })
done(null,l)
}
} }
}) })
return true // remove myself from listeners return true // remove myself from listeners

View File

@ -16,12 +16,14 @@ module.exports = function(boardsAPI){
}, },
render: function(){ render: function(){
if(this.props.comment){ if(this.props.comment){
var Comments = this.props.comment.comments || require('comments.jsx')(boardsAPI)
return <div className="comment"><hr/> return <div className="comment"><hr/>
<div className="icons"> <div className="icons">
<UserID id={this.props.comment.op} /> <UserID id={this.props.comment.op} />
<Clock date={this.props.comment.date} /> <Clock date={this.props.comment.date} />
</div> </div>
<Markdown source={this.props.comment.text} /> <Markdown source={this.props.comment.text} />
<Comments className="shifted" parent={this.props.comment.hash} adminID={this.props.adminID} board={this.props.board}/>
<hr/></div> <hr/></div>
} else { } else {
return <div><hr/>Invalid Comment<hr/></div> return <div><hr/>Invalid Comment<hr/></div>

View File

@ -21,10 +21,12 @@ module.exports = function(boardsAPI){
}) })
}, },
getComments: function(){ getComments: function(){
return this.state.comments.map(cmnt => (<Comment key={cmnt.hash} comment={cmnt} />) ) if(this.state.comments.length > 0)
return this.state.comments.map(cmnt => (<Comment key={cmnt.hash} comment={cmnt} comments={this} adminID={this.props.adminID} board={this.props.board}/>) )
else return <div></div>
}, },
render: function(){ render: function(){
return <div>{this.getComments()}</div> return <div className={this.props.className+' comments'} >{this.getComments()}</div>
} }
}) })
} }

View File

@ -71,7 +71,7 @@ module.exports = function(boardsAPI){
<h1>{this.state.name}</h1> <h1>{this.state.name}</h1>
<Markdown source={this.state.description} skipHtml={true} /> <Markdown source={this.state.description} skipHtml={true} />
<hr/> <hr/>
<h5 className="light">@{uid}</h5> <div className="light breaker">@{uid}</div>
{this.state.boards.map(n => { {this.state.boards.map(n => {
return <h6 className="light" key={uid+'/'+n.name}> return <h6 className="light" key={uid+'/'+n.name}>
<Link to={'/@'+uid+'/'+n.name}># {n.name}</Link> <Link to={'/@'+uid+'/'+n.name}># {n.name}</Link>

View File

@ -58,6 +58,10 @@ a:hover {
color: #707070 color: #707070
} }
.breaker {
word-break: break-all;
}
.app { .app {
padding-top: 9rem padding-top: 9rem
} }
@ -107,6 +111,9 @@ a:hover {
margin-right: 1rem; margin-right: 1rem;
} }
.shifted {
margin-left: 2rem;
}
.navbar { .navbar {
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;