view changes to ExpendedComments.js, show Collapse/Expand on hover
This commit is contained in:
parent
23144bc180
commit
3186a1f8ca
@ -1,14 +1,23 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
const ExpandedComment = props => {
|
const ExpandedComment = props => {
|
||||||
const { text } = props
|
|
||||||
return (
|
return (
|
||||||
<li key={props.id}>
|
<li
|
||||||
|
className=""
|
||||||
|
key={props.id}
|
||||||
|
onMouseEnter={() => props.showCollapseLink(props.id, true)}
|
||||||
|
onMouseLeave={() => props.showCollapseLink(props.id, false)}
|
||||||
|
>
|
||||||
<div className="media bg bg-dark">
|
<div className="media bg bg-dark">
|
||||||
<img alt="profile" src="anon.jpeg" height={64} />
|
<img alt="profile" src="anon.jpeg" height={64} />
|
||||||
|
|
||||||
<div className="media-body ml-3 my-auto">
|
<div className="media-body ml-3 my-auto">
|
||||||
<a href="#user">username</a>
|
<a className="" href="#user">
|
||||||
<div>
|
username
|
||||||
<small>July 9 2019, 01:32:27 UTC</small>
|
</a>
|
||||||
|
</div>
|
||||||
|
<div className="white">
|
||||||
|
<small>{props.createdAt}</small>
|
||||||
{props.replies.length > 0 ? (
|
{props.replies.length > 0 ? (
|
||||||
<span
|
<span
|
||||||
className="a ml-3"
|
className="a ml-3"
|
||||||
@ -16,6 +25,7 @@ const ExpandedComment = props => {
|
|||||||
fontVariant: 'small-caps',
|
fontVariant: 'small-caps',
|
||||||
color: 'blue',
|
color: 'blue',
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
|
display: props.displayCollapse || 'none',
|
||||||
}}
|
}}
|
||||||
onClick={() => props.toggleCollapse(props.id)}
|
onClick={() => props.toggleCollapse(props.id)}
|
||||||
>
|
>
|
||||||
@ -24,11 +34,16 @@ const ExpandedComment = props => {
|
|||||||
) : (
|
) : (
|
||||||
''
|
''
|
||||||
)}
|
)}
|
||||||
|
<a
|
||||||
|
className="float-right ml-2"
|
||||||
|
href="#replies"
|
||||||
|
onClick={props.replyToComment}
|
||||||
|
>
|
||||||
|
reply
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div className="">{props.text}</div>
|
||||||
<div>{text}</div>
|
|
||||||
<a href="#replies">reply</a>
|
|
||||||
</li>
|
</li>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,16 @@ class ThreadList extends React.Component {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
this.toggleCollapse = this.toggleCollapse.bind(this)
|
this.toggleCollapse = this.toggleCollapse.bind(this)
|
||||||
|
this.showCollapseLink = this.showCollapseLink.bind(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
showCollapseLink(id, collapsed) {
|
||||||
|
this.setState({ displayCollapse: 'block' })
|
||||||
|
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)
|
||||||
|
this.setState({ comments: otherComments.concat(comment) })
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleCollapse(id) {
|
toggleCollapse(id) {
|
||||||
@ -24,18 +34,23 @@ class ThreadList extends React.Component {
|
|||||||
(!c.parentId && !this.props.threadLevel) ||
|
(!c.parentId && !this.props.threadLevel) ||
|
||||||
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)
|
console.log('showing comments for thread', this.props.threadLevel, comments)
|
||||||
return (
|
return (
|
||||||
<ul className="list-unstyled">
|
<ul className="list-unstyled">
|
||||||
{comments.map(comment => {
|
{comments.map(comment => {
|
||||||
// TODO comments aren't sorted by time
|
// TODO comments aren't sorted by time
|
||||||
if (!comment.replies.length > 0) {
|
if (comment.replies && comment.replies.length === 0) {
|
||||||
return (
|
return (
|
||||||
<div className="ml-3" key={uuid()}>
|
<div className="ml-3" key={uuid()}>
|
||||||
<SingleComment
|
<SingleComment
|
||||||
threadLevel={this.props.threadLevel}
|
threadLevel={this.props.threadLevel}
|
||||||
|
showCollapseLink={this.showCollapseLink}
|
||||||
toggleCollapse={this.toggleCollapse}
|
toggleCollapse={this.toggleCollapse}
|
||||||
{...comment}
|
{...comment}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@ -43,12 +58,14 @@ class ThreadList extends React.Component {
|
|||||||
<div className="ml-3" key={uuid()}>
|
<div className="ml-3" key={uuid()}>
|
||||||
<SingleComment
|
<SingleComment
|
||||||
threadLevel={this.props.threadLevel}
|
threadLevel={this.props.threadLevel}
|
||||||
|
showCollapseLink={this.showCollapseLink}
|
||||||
toggleCollapse={this.toggleCollapse}
|
toggleCollapse={this.toggleCollapse}
|
||||||
{...comment}
|
{...comment}
|
||||||
/>
|
/>
|
||||||
{!comment.collapsed && (
|
{!comment.collapsed && (
|
||||||
<ThreadList
|
<ThreadList
|
||||||
threadLevel={comment.id}
|
threadLevel={comment.id}
|
||||||
|
showCollapseLink={this.showCollapseLink}
|
||||||
comments={this.props.comments}
|
comments={this.props.comments}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
Loading…
Reference in New Issue
Block a user