diff --git a/client/coral-embed-stream/src/Comment.js b/client/coral-embed-stream/src/Comment.js index f734bce0b..93c89ffb0 100644 --- a/client/coral-embed-stream/src/Comment.js +++ b/client/coral-embed-stream/src/Comment.js @@ -26,6 +26,11 @@ class Comment extends React.Component { } static propTypes = { + reactKey: PropTypes.string.isRequired, + + // id of currently opened ReplyBox. tracked in Stream.js + activeReplyBox: PropTypes.string.isRequired, + setActiveReplyBox: PropTypes.func.isRequired, refetch: PropTypes.func.isRequired, showSignInDialog: PropTypes.func.isRequired, postAction: PropTypes.func.isRequired, @@ -60,15 +65,6 @@ class Comment extends React.Component { }).isRequired } - onReplyBoxClick = () => { - if (this.props.currentUser) { - this.setState({replyBoxVisible: !this.state.replyBoxVisible}); - } else { - const offset = document.getElementById(`c_${this.props.comment.id}`).getBoundingClientRect().top - 75; - this.props.showSignInDialog(offset); - } - } - render () { const { comment, @@ -81,6 +77,8 @@ class Comment extends React.Component { addNotification, showSignInDialog, postAction, + setActiveReplyBox, + activeReplyBox, deleteAction } = this.props; @@ -106,7 +104,7 @@ class Comment extends React.Component {
setActiveReplyBox(comment.id)} parentCommentId={parentId || comment.id} currentUserId={currentUser && currentUser.id} banned={false} /> @@ -130,13 +128,13 @@ class Comment extends React.Component {
{ - this.state.replyBoxVisible + activeReplyBox === comment.id ? { - console.log('replyPostedHandler'); - this.setState({replyBoxVisible: false}); + setActiveReplyBox(''); refetch(); }} + setActiveReplyBox={setActiveReplyBox} parentId={parentId || comment.id} addNotification={addNotification} authorId={currentUser.id} @@ -149,6 +147,8 @@ class Comment extends React.Component { comment.replies.map(reply => { return ; }) diff --git a/client/coral-embed-stream/src/Stream.js b/client/coral-embed-stream/src/Stream.js index 73842a947..65743e6c7 100644 --- a/client/coral-embed-stream/src/Stream.js +++ b/client/coral-embed-stream/src/Stream.js @@ -1,49 +1,72 @@ import React, {PropTypes} from 'react'; import Comment from './Comment'; -const Stream = ({ - comments, - currentUser, - asset, - postItem, - addNotification, - postAction, - deleteAction, - showSignInDialog, - refetch -}) => { - return ( -
- { - comments.map(comment => { - return ; - }) - } -
- ); -}; +class Stream extends React.Component { -Stream.propTypes = { - refetch: PropTypes.func.isRequired, - addNotification: PropTypes.func.isRequired, - postItem: PropTypes.func.isRequired, - asset: PropTypes.object.isRequired, - comments: PropTypes.array.isRequired, - currentUser: PropTypes.shape({ - displayName: PropTypes.string, - id: PropTypes.string - }) -}; + static propTypes = { + refetch: PropTypes.func.isRequired, + addNotification: PropTypes.func.isRequired, + postItem: PropTypes.func.isRequired, + asset: PropTypes.object.isRequired, + comments: PropTypes.array.isRequired, + currentUser: PropTypes.shape({ + displayName: PropTypes.string, + id: PropTypes.string + }) + } + + constructor(props) { + super(props); + this.state = {activeReplyBox: ''}; + this.setActiveReplyBox = this.setActiveReplyBox.bind(this); + } + + setActiveReplyBox (reactKey) { + if (!this.props.currentUser) { + const offset = document.getElementById(`c_${reactKey}`).getBoundingClientRect().top - 75; + this.props.showSignInDialog(offset); + } else { + this.setState({activeReplyBox: reactKey}); + } + } + + render () { + const { + comments, + currentUser, + asset, + postItem, + addNotification, + postAction, + deleteAction, + showSignInDialog, + refetch + } = this.props; + + return ( +
+ { + comments.map(comment => { + return ; + }) + } +
+ ); + } +} export default Stream; diff --git a/client/coral-plugin-commentbox/CommentBox.js b/client/coral-plugin-commentbox/CommentBox.js index f368953a7..258681a08 100644 --- a/client/coral-plugin-commentbox/CommentBox.js +++ b/client/coral-plugin-commentbox/CommentBox.js @@ -13,6 +13,7 @@ class CommentBox extends Component { // comments: PropTypes.array, commentPostedHandler: PropTypes.func, postItem: PropTypes.func.isRequired, + cancelButtonClicked: PropTypes.func, assetId: PropTypes.string.isRequired, parentId: PropTypes.string, authorId: PropTypes.string.isRequired, @@ -89,7 +90,14 @@ class CommentBox extends Component { render () { const {styles, isReply, authorId, charCount} = this.props; + let {cancelButtonClicked} = this.props; const length = this.state.body.length; + + if (isReply && typeof cancelButtonClicked !== 'function') { + console.warn('the CommentBox component should have a cancelButtonClicked callback defined if it lives in a Reply'); + cancelButtonClicked = () => {}; + } + return
@@ -115,6 +123,19 @@ class CommentBox extends Component { }
+ { + isReply && ( + + ) + } { authorId && (