show nested collapsed comments (#3)
This commit is contained in:
parent
3186a1f8ca
commit
e8e3729f5f
@ -27,18 +27,14 @@ const ExpandedComment = props => {
|
|||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
display: props.displayCollapse || 'none',
|
display: props.displayCollapse || 'none',
|
||||||
}}
|
}}
|
||||||
onClick={() => props.toggleCollapse(props.id)}
|
onClick={() => props.toggleCollapse(props.id, !props.collapsed)}
|
||||||
>
|
>
|
||||||
collapse
|
{props.collapsed ? 'expand' : 'collapse'}
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
''
|
''
|
||||||
)}
|
)}
|
||||||
<a
|
<a className="float-right ml-2" href="#replies">
|
||||||
className="float-right ml-2"
|
|
||||||
href="#replies"
|
|
||||||
onClick={props.replyToComment}
|
|
||||||
>
|
|
||||||
reply
|
reply
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,7 +3,7 @@ import ExpandedComment from './ExpandedComment'
|
|||||||
import CollapsedComment from './CollapsedComment'
|
import CollapsedComment from './CollapsedComment'
|
||||||
|
|
||||||
const SingleComment = props => {
|
const SingleComment = props => {
|
||||||
if (props.collapsed) return <CollapsedComment {...props} />
|
if (props.hidden) return <CollapsedComment {...props} />
|
||||||
return <ExpandedComment {...props} />
|
return <ExpandedComment {...props} />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,13 +18,28 @@ class ThreadList extends React.Component {
|
|||||||
this.setState({ comments: otherComments.concat(comment) })
|
this.setState({ comments: otherComments.concat(comment) })
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleCollapse(id) {
|
toggleCollapse(id, collapsed) {
|
||||||
// select passed comment from the state, toggle it and put it all back
|
|
||||||
const otherComments = this.props.comments.filter(c => c.id !== id)
|
const otherComments = this.props.comments.filter(c => c.id !== id)
|
||||||
const comment = this.props.comments.find(c => c.id === id)
|
var parent = this.props.comments.find(c => c.id === id)
|
||||||
comment['collapsed'] = !comment.collapsed
|
console.log('toggling', parent)
|
||||||
console.log('toggled: ', comment)
|
parent['collapsed'] = collapsed
|
||||||
|
if (!collapsed) {
|
||||||
|
// when parent was a reply in a previously collapsed thread
|
||||||
|
// and is to be expanded it will be marked hidden
|
||||||
|
// and needs to be unhidden
|
||||||
|
parent['hidden'] = false
|
||||||
|
}
|
||||||
|
this.setState({ comments: otherComments.concat(parent) })
|
||||||
|
parent.replies.map(comment => this.toggleReplies(comment.id, collapsed))
|
||||||
|
}
|
||||||
|
toggleReplies(id, collapsed) {
|
||||||
|
const otherComments = this.props.comments.filter(c => c.id !== id)
|
||||||
|
var comment = this.props.comments.find(c => c.id === id)
|
||||||
|
comment['hidden'] = collapsed
|
||||||
this.setState({ comments: otherComments.concat(comment) })
|
this.setState({ comments: otherComments.concat(comment) })
|
||||||
|
if (comment.replies) {
|
||||||
|
comment.replies.map(c => this.toggleReplies(c.id, collapsed))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -62,13 +77,11 @@ class ThreadList extends React.Component {
|
|||||||
toggleCollapse={this.toggleCollapse}
|
toggleCollapse={this.toggleCollapse}
|
||||||
{...comment}
|
{...comment}
|
||||||
/>
|
/>
|
||||||
{!comment.collapsed && (
|
|
||||||
<ThreadList
|
<ThreadList
|
||||||
threadLevel={comment.id}
|
threadLevel={comment.id}
|
||||||
showCollapseLink={this.showCollapseLink}
|
showCollapseLink={this.showCollapseLink}
|
||||||
comments={this.props.comments}
|
comments={this.props.comments}
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user