1
0

don't rerender on hover for collapse/expand link

This commit is contained in:
data 2019-07-14 15:03:12 +02:00
parent e212b52f9b
commit 03311238e8
3 changed files with 14 additions and 20 deletions

View File

@ -1,3 +1,15 @@
.replies { .replies {
margin-left: 1em; margin-left: 1em;
} }
a:hover {
text-decoration: none;
color: #007bff;
}
.comment-meta a {
display: none;
}
.comment-meta:hover a {
display: inline;
text-decoration: none;
color: #007bff;
}

View File

@ -3,18 +3,13 @@ import CommentReply from './CommentReply'
const ExpandedComment = props => { const ExpandedComment = props => {
return ( return (
<li <li key={props.id}>
className=""
key={props.id}
onMouseEnter={() => props.showCollapseLink(props.id, true)}
onMouseLeave={() => props.showCollapseLink(props.id, false)}
>
<div id="media-image" className="media bg bg-dark"> <div id="media-image" className="media bg bg-dark">
<img alt="profile" src="anon.jpeg" height={64} /> <img alt="profile" src="anon.jpeg" height={64} />
<div id="media-body" className="media-body ml-3 my-auto"> <div id="media-body" className="media-body ml-3 my-auto">
<a href="#user">username</a> <a href="#user">username</a>
<div className="text-white-50"> <div className="comment-meta text-white-50">
<small>{props.createdAt}</small> <small>{props.createdAt}</small>
{props.replies.length > 0 ? ( {props.replies.length > 0 ? (
<a <a
@ -22,7 +17,6 @@ const ExpandedComment = props => {
className="ml-3" className="ml-3"
style={{ style={{
fontVariant: 'small-caps', fontVariant: 'small-caps',
display: props.displayCollapse || 'none',
}} }}
onClick={() => onClick={() =>
props.toggleCollapse(props.id, !props.collapsedThread) props.toggleCollapse(props.id, !props.collapsedThread)

View File

@ -7,19 +7,9 @@ class ThreadList extends React.Component {
super() super()
this.state = { activeReplyId: null } this.state = { activeReplyId: null }
this.toggleCollapse = this.toggleCollapse.bind(this) this.toggleCollapse = this.toggleCollapse.bind(this)
this.showCollapseLink = this.showCollapseLink.bind(this)
this.showReply = this.showReply.bind(this) this.showReply = this.showReply.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, collapsed) { toggleCollapse(id, collapsed) {
const otherComments = this.props.comments.filter(c => c.id !== id) const otherComments = this.props.comments.filter(c => c.id !== id)
var parent = this.props.comments.find(c => c.id === id) var parent = this.props.comments.find(c => c.id === id)
@ -70,7 +60,6 @@ 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}
showReply={this.showReply} showReply={this.showReply}
submitComment={this.props.submitComment} submitComment={this.props.submitComment}
@ -80,7 +69,6 @@ class ThreadList extends React.Component {
{comment.replies && ( {comment.replies && (
<ThreadList <ThreadList
threadLevel={comment.id} threadLevel={comment.id}
showCollapseLink={this.showCollapseLink}
comments={this.props.comments} comments={this.props.comments}
submitComment={this.props.submitComment} submitComment={this.props.submitComment}
/> />