diff --git a/webclient/src/Comments.js b/webclient/src/Comments.js index 152585a..7d8f6ef 100644 --- a/webclient/src/Comments.js +++ b/webclient/src/Comments.js @@ -18,6 +18,8 @@ class Article extends React.Component { this.state = { story: cache[id] || false, error: false, + collapsed: [], + expanded: [], }; } @@ -49,22 +51,54 @@ class Article extends React.Component { ); } + collapseComment(cid) { + this.setState(prevState => ({ + ...prevState, + collapsed: [...prevState.collapsed, cid], + expanded: prevState.expanded.filter(x => x !== cid), + })); + } + + expandComment(cid) { + this.setState(prevState => ({ + ...prevState, + collapsed: prevState.collapsed.filter(x => x !== cid), + expanded: [...prevState.expanded, cid], + })); + } + + countComments(c) { + return c.comments.reduce((sum, x) => sum + this.countComments(x), 1); + } + displayComment(story, c, level) { + const cid = c.author+c.date; + + const collapsed = this.state.collapsed.includes(cid); + const expanded = this.state.expanded.includes(cid); + + const hidden = collapsed || (level == 4 && !expanded); + const hasChildren = c.comments.length !== 0; + return ( -
{c.author === story.author ? '[OP]' : ''} {c.author || '[Deleted]'}
- |
[replies snipped]