-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from kadirahq/delete-method
Add a deleteComment method on datastore
- Loading branch information
Showing
8 changed files
with
166 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { Component } from 'react'; | ||
import moment from 'moment'; | ||
import renderHTML from 'react-render-html'; | ||
import insertCss from 'insert-css'; | ||
import style from './style'; | ||
import commentCSS from './style.css'; | ||
|
||
insertCss(commentCSS); | ||
|
||
export default class CommentItem extends Component { | ||
constructor(props, ...args) { | ||
super(props, ...args); | ||
this.state = { hovered: false }; | ||
this.mouseEnter = this.mouseEnter.bind(this); | ||
this.mouseLeave = this.mouseLeave.bind(this); | ||
this.deleteComment = this.deleteComment.bind(this); | ||
} | ||
|
||
mouseEnter() { | ||
this.setState({ hovered: true }); | ||
} | ||
|
||
mouseLeave() { | ||
this.setState({ hovered: false }); | ||
} | ||
|
||
deleteComment() { | ||
this.props.deleteComment(); | ||
} | ||
|
||
renderDelete() { | ||
return ( | ||
<a | ||
href="#" | ||
style={style.commentDelete} | ||
onClick={this.props.deleteComment}> | ||
delete | ||
</a> | ||
); | ||
} | ||
|
||
render() { | ||
const comment = this.props.comment; | ||
let commentStyle = style.commentItem; | ||
if (comment.loading) { | ||
commentStyle = style.commentItemloading; | ||
} | ||
|
||
const time = moment(new Date(comment.time), "YYYYMMDD").fromNow(); | ||
const body = renderHTML(`<span>${comment.text}</span>`); | ||
const showDelete = this.state.hovered && this.props.ownComment; | ||
|
||
return ( | ||
<div style={commentStyle} onMouseEnter={this.mouseEnter} onMouseLeave={this.mouseLeave}> | ||
<div style={style.commentAside}> | ||
<img style={style.commentAvatar} src={comment.user.avatar} /> | ||
</div> | ||
<div className="comment-content" style={style.commentContent}> | ||
<div style={style.commentHead}> | ||
<span style={style.commentUser}>{comment.user.name}</span> | ||
<span style={style.commentTime}>{time}</span> | ||
</div> | ||
<span style={style.commentText}>{body}</span> | ||
{showDelete ? this.renderDelete() : null} | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const commentItem = { | ||
display: 'flex', | ||
paddingBottom: '5px', | ||
WebkitFontSmoothing: 'antialiased', | ||
transition: 'opacity 0.5s', | ||
} | ||
|
||
export default { | ||
commentItem: { | ||
...commentItem, | ||
}, | ||
commentItemloading: { | ||
...commentItem, | ||
opacity: 0.25, | ||
}, | ||
commentAside: { | ||
margin: '5px 10px 0 0', | ||
}, | ||
commentAvatar: { | ||
width: 32, | ||
height: 32, | ||
borderRadius: 5, | ||
}, | ||
commentContent: { | ||
position: 'relative', | ||
flex: 1, | ||
}, | ||
commentHead: { | ||
// | ||
}, | ||
commentUser: { | ||
fontFamily: 'sans-serif', | ||
fontSize: 13, | ||
lineHeight: 1, | ||
fontWeight: 'bold', | ||
marginRight: 5, | ||
}, | ||
commentTime: { | ||
fontFamily: 'sans-serif', | ||
fontSize: 11, | ||
lineHeight: 1, | ||
color: 'rgb(150, 150, 150)', | ||
}, | ||
commentText: { | ||
fontFamily: 'sans-serif', | ||
fontSize: 13, | ||
lineHeight: 1.7, | ||
maxWidth: 650, | ||
}, | ||
commentDelete: { | ||
fontFamily: 'sans-serif', | ||
position: 'absolute', | ||
top: 2, | ||
right: 0, | ||
fontSize: 11, | ||
color: 'rgb(200, 200, 200)', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters