Compare commits
No commits in common. "master" and "recursion" have entirely different histories.
@ -1,45 +1,34 @@
|
||||
import React from 'react'
|
||||
|
||||
const ExpandedComment = props => {
|
||||
const { text } = props
|
||||
return (
|
||||
<li
|
||||
className=""
|
||||
key={props.id}
|
||||
onMouseEnter={() => props.showCollapseLink(props.id, true)}
|
||||
onMouseLeave={() => props.showCollapseLink(props.id, false)}
|
||||
>
|
||||
<li key={props.id}>
|
||||
<div className="media bg bg-dark">
|
||||
<img alt="profile" src="anon.jpeg" height={64} />
|
||||
|
||||
<div className="media-body ml-3 my-auto">
|
||||
<a className="" href="#user">
|
||||
username
|
||||
</a>
|
||||
</div>
|
||||
<div className="white">
|
||||
<small>{props.createdAt}</small>
|
||||
{props.replies.length > 0 ? (
|
||||
<span
|
||||
className="a ml-3"
|
||||
style={{
|
||||
fontVariant: 'small-caps',
|
||||
color: 'blue',
|
||||
cursor: 'pointer',
|
||||
display: props.displayCollapse || 'none',
|
||||
}}
|
||||
onClick={() => props.toggleCollapse(props.id, !props.collapsed)}
|
||||
>
|
||||
{props.collapsed ? 'expand' : 'collapse'}
|
||||
</span>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
<a className="float-right ml-2" href="#replies">
|
||||
reply
|
||||
</a>
|
||||
<a href="#user">username</a>
|
||||
<div>
|
||||
<small>July 9 2019, 01:32:27 UTC</small>
|
||||
{props.replies.length > 0 ? (
|
||||
<span
|
||||
className="a ml-3"
|
||||
style={{
|
||||
fontVariant: 'small-caps',
|
||||
color: 'blue',
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
onClick={() => props.toggleCollapse(props.id)}
|
||||
>
|
||||
collapse
|
||||
</span>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="">{props.text}</div>
|
||||
<div>{text}</div>
|
||||
<a href="#replies">reply</a>
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import ExpandedComment from './ExpandedComment'
|
||||
import CollapsedComment from './CollapsedComment'
|
||||
|
||||
const SingleComment = props => {
|
||||
if (props.hidden) return <CollapsedComment {...props} />
|
||||
if (props.collapsed) return <CollapsedComment {...props} />
|
||||
return <ExpandedComment {...props} />
|
||||
}
|
||||
|
||||
|
@ -6,42 +6,17 @@ class ThreadList extends React.Component {
|
||||
constructor() {
|
||||
super()
|
||||
this.toggleCollapse = this.toggleCollapse.bind(this)
|
||||
this.showCollapseLink = this.showCollapseLink.bind(this)
|
||||
}
|
||||
|
||||
showCollapseLink(id, collapsed) {
|
||||
this.setState({ displayCollapse: 'block' })
|
||||
toggleCollapse(id) {
|
||||
// select passed comment from the state, toggle it and put it all back
|
||||
const otherComments = this.props.comments.filter(c => c.id !== id)
|
||||
const comment = this.props.comments.find(c => c.id === id)
|
||||
comment['displayCollapse'] = collapsed
|
||||
//console.log('displayed collapse for: ', comment)
|
||||
comment['collapsed'] = !comment.collapsed
|
||||
console.log('toggled: ', comment)
|
||||
this.setState({ comments: otherComments.concat(comment) })
|
||||
}
|
||||
|
||||
toggleCollapse(id, collapsed) {
|
||||
const otherComments = this.props.comments.filter(c => c.id !== id)
|
||||
var parent = this.props.comments.find(c => c.id === id)
|
||||
console.log('toggling', parent)
|
||||
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) })
|
||||
if (comment.replies) {
|
||||
comment.replies.map(c => this.toggleReplies(c.id, collapsed))
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const comments = this.props.comments.filter(
|
||||
// only show comments for this parent / thread
|
||||
@ -49,20 +24,16 @@ class ThreadList extends React.Component {
|
||||
(!c.parentId && !this.props.threadLevel) ||
|
||||
c.parentId === this.props.threadLevel
|
||||
)
|
||||
if (comments.length === 0) {
|
||||
return ''
|
||||
}
|
||||
console.log('showing comments for thread', this.props.threadLevel, comments)
|
||||
return (
|
||||
<ul className="list-unstyled">
|
||||
{comments.map(comment => {
|
||||
// TODO comments aren't sorted by time
|
||||
if (comment.replies && comment.replies.length === 0) {
|
||||
if (!comment.replies.length > 0) {
|
||||
return (
|
||||
<div className="ml-3" key={uuid()}>
|
||||
<SingleComment
|
||||
threadLevel={this.props.threadLevel}
|
||||
showCollapseLink={this.showCollapseLink}
|
||||
toggleCollapse={this.toggleCollapse}
|
||||
{...comment}
|
||||
/>
|
||||
@ -73,15 +44,15 @@ class ThreadList extends React.Component {
|
||||
<div className="ml-3" key={uuid()}>
|
||||
<SingleComment
|
||||
threadLevel={this.props.threadLevel}
|
||||
showCollapseLink={this.showCollapseLink}
|
||||
toggleCollapse={this.toggleCollapse}
|
||||
{...comment}
|
||||
/>
|
||||
<ThreadList
|
||||
threadLevel={comment.id}
|
||||
showCollapseLink={this.showCollapseLink}
|
||||
comments={this.props.comments}
|
||||
/>
|
||||
{!comment.collapsed && (
|
||||
<ThreadList
|
||||
threadLevel={comment.id}
|
||||
comments={this.props.comments}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user