From 6282c39f3ae9c1adc7c986e27975350d7e062df3 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Mon, 23 Jan 2017 16:52:16 -0700 Subject: [PATCH] merge remote. can reply to a comment --- client/coral-embed-stream/src/Comment.js | 226 +++++++++++------- client/coral-embed-stream/src/Embed.js | 33 ++- client/coral-embed-stream/src/Stream.js | 6 +- .../src/graphql/mutations/index.js | 4 +- client/coral-plugin-commentbox/CommentBox.js | 71 +++--- client/coral-plugin-flags/FlagButton.js | 2 +- client/coral-plugin-replies/ReplyBox.js | 31 ++- client/coral-plugin-replies/ReplyButton.js | 32 ++- 8 files changed, 245 insertions(+), 160 deletions(-) diff --git a/client/coral-embed-stream/src/Comment.js b/client/coral-embed-stream/src/Comment.js index 6e3744aab..21e98ae64 100644 --- a/client/coral-embed-stream/src/Comment.js +++ b/client/coral-embed-stream/src/Comment.js @@ -11,103 +11,157 @@ import PermalinkButton from 'coral-plugin-permalinks/PermalinkButton'; // import AuthorName from '../../coral-plugin-author-name/AuthorName'; import Content from '../../coral-plugin-commentcontent/CommentContent'; import PubDate from '../../coral-plugin-pubdate/PubDate'; -// import {ReplyBox, ReplyButton} from '../../coral-plugin-replies'; +import {ReplyBox, ReplyButton} from 'coral-plugin-replies'; import FlagComment from '../../coral-plugin-flags/FlagComment'; import LikeButton from '../../coral-plugin-likes/LikeButton'; const getAction = (type, comment) => comment.actions.filter((a) => a.type === type)[0]; -const Comment = ({comment, currentUser, asset, depth, showSignInDialog, postAction, deleteAction}) => { - const like = getAction('LIKE', comment); - const flag = getAction('FLAG', comment); - return ( -
-
- {/* */} - - -
- {/* - - */} - -
-
- +
+ {/* - -
- { - comment.replies && - comment.replies.map(reply => { - return */} + + + + { + currentUser + ?
+ { + console.log('reply button click'); + this.setState({replyBoxVisible: !this.state.replyBoxVisible}); + }} + parentCommentId={comment.id} + currentUserId={currentUser.id} + banned={false} /> + +
+ : null + } +
+ { + currentUser + ? ; - }) - } + currentUser={currentUser} /> + : null + } -
- ); -}; + +
+ { + this.state.replyBoxVisible + ? + : null + } + { + comment.replies && + comment.replies.map(reply => { + return ; + }) + } -Comment.propTypes = { - depth: PropTypes.number.isRequired, - asset: PropTypes.shape({ - id: PropTypes.string, - title: PropTypes.string, - url: PropTypes.string - }).isRequired, - currentUser: PropTypes.object, - comment: PropTypes.shape({ - depth: PropTypes.number, - actions: PropTypes.array.isRequired, - body: PropTypes.string.isRequired, - id: PropTypes.string.isRequired, - replies: PropTypes.arrayOf( - PropTypes.shape({ - body: PropTypes.string.isRequired, - id: PropTypes.string.isRequired - }) - ), - user: PropTypes.shape({ - id: PropTypes.string.isRequired, - name: PropTypes.string.isRequired - }).isRequired - }).isRequired -}; + + ); + } +} export default Comment; diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index cd55c13cd..8ddc215cb 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -102,7 +102,7 @@ class Embed extends Component { // const banned = (this.props.userData.status === 'banned'); - const {loading, asset} = this.props.data; + const {loading, asset, refetch} = this.props.data; // const {status, moderation, closedMessage, charCount, charCountEnable} = asset.settings; @@ -129,24 +129,31 @@ class Embed extends Component { enable={asset.settings.infoBoxEnable} /> }> - + { + user + ? + : null + } :

{asset.settings.closedMessage}

} {!loggedIn && } { +const Stream = ({comments, currentUser, asset, postItem, addNotification, postAction, deleteAction, showSignInDialog}) => { return (
{ comments.map(comment => { return ({ - postItem: ({asset_id, body}) => { + postItem: ({asset_id, body, parent_id} /*, type */) => { return mutate({ variables: { asset_id, body, - parent_id: null + parent_id } }); }}), diff --git a/client/coral-plugin-commentbox/CommentBox.js b/client/coral-plugin-commentbox/CommentBox.js index ff9bf7e39..90113180c 100644 --- a/client/coral-plugin-commentbox/CommentBox.js +++ b/client/coral-plugin-commentbox/CommentBox.js @@ -8,11 +8,13 @@ const name = 'coral-plugin-commentbox'; class CommentBox extends Component { static propTypes = { - postItem: PropTypes.func, - updateItem: PropTypes.func, - id: PropTypes.string, - comments: PropTypes.array, - reply: PropTypes.bool, + postItem: PropTypes.func.isRequired, + // updateItem: PropTypes.func, + assetId: PropTypes.string.isRequired, + parentId: PropTypes.string, + authorId: PropTypes.string.isRequired, + // comments: PropTypes.array, + isReply: PropTypes.bool.isRequired, canPost: PropTypes.bool, currentUser: PropTypes.object } @@ -25,33 +27,36 @@ class CommentBox extends Component { postComment = () => { const { postItem, - updateItem, - id, - parent_id, - child_id, + // updateItem, + assetId, + parentId, + // child_id, addNotification, - appendItemArray, - author + // appendItemArray, + authorId } = this.props; let comment = { body: this.state.body, - asset_id: id, - author_id: author.id + asset_id: assetId, + author_id: authorId, + parent_id: parentId }; - let related; - let parent_type; - if (parent_id) { - comment.parent_id = parent_id; - related = 'children'; - parent_type = 'comments'; - } else { - related = 'comments'; - parent_type = 'assets'; - } - if (child_id || parent_id) { - updateItem(child_id || parent_id, 'showReply', false, 'comments'); - } + + console.log('CommentBox.parentId', parentId); + // let related; + // let parent_type; + // if (parent_id) { + // comment.parent_id = parent_id; + // related = 'children'; + // parent_type = 'comments'; + // } else { + // related = 'comments'; + // parent_type = 'assets'; + // } + // if (child_id || parent_id) { + // updateItem(child_id || parent_id, 'showReply', false, 'comments'); + // } if (this.props.charCount && this.state.body.length > this.props.charCount) { return; @@ -59,13 +64,13 @@ class CommentBox extends Component { postItem(comment, 'comments') .then(({data}) => { const postedComment = data.createComment; - const commentId = postedComment.id; + // const commentId = postedComment.id; if (postedComment.status === 'rejected') { addNotification('error', lang.t('comment-post-banned-word')); } else if (postedComment.status === 'PREMOD') { addNotification('success', lang.t('comment-post-notif-premod')); } else { - appendItemArray(parent_id || id, related, commentId, !parent_id, parent_type); + // appendItemArray(parent_id || id, related, commentId, !parent_id, parent_type); addNotification('success', 'Your comment has been posted.'); } }) @@ -74,23 +79,23 @@ class CommentBox extends Component { } render () { - const {styles, reply, author, charCount} = this.props; + const {styles, isReply, authorId, charCount} = this.props; const length = this.state.body.length; return