diff --git a/client/coral-embed-stream/src/Comment.js b/client/coral-embed-stream/src/Comment.js index c5158e31a..2817f4675 100644 --- a/client/coral-embed-stream/src/Comment.js +++ b/client/coral-embed-stream/src/Comment.js @@ -13,9 +13,10 @@ import Content from '../../coral-plugin-commentcontent/CommentContent'; import PubDate from '../../coral-plugin-pubdate/PubDate'; // import {ReplyBox, ReplyButton} from '../../coral-plugin-replies'; // import FlagComment from '../../coral-plugin-flags/FlagComment'; -// import LikeButton from '../../coral-plugin-likes/LikeButton'; +import LikeButton from '../../coral-plugin-likes/LikeButton'; -const Comment = ({comment, currentUser, asset, depth}) => { +const Comment = ({comment, currentUser, asset, depth, showSignInDialog, postAction, deleteAction}) => { + const like = comment.actions.filter((a) => a.type === 'LIKE')[0]; return (
{
- + {/* + + */} +
- + {/* + + */}
{ @@ -49,6 +62,10 @@ const Comment = ({comment, currentUser, asset, depth}) => { depth={depth + 1} asset={asset} currentUser={currentUser} + currentUser={currentUser} + postAction={postAction} + deleteAction={deleteAction} + showSignInDialog={showSignInDialog} key={reply.id} comment={reply} />; }) diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index 5a44f8532..4d44a10b6 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -3,7 +3,7 @@ import React, {Component, PropTypes} from 'react'; import {compose} from 'react-apollo'; import {connect} from 'react-redux'; -import {postComment} from './graphql/mutations'; +import {postComment, postAction, deleteAction} from './graphql/mutations'; import {queryStream} from './graphql/queries'; import { @@ -149,6 +149,9 @@ class Embed extends Component { ({ export default compose( connect(mapStateToProps, mapDispatchToProps), postComment, + postAction, + deleteAction, queryStream )(Embed); diff --git a/client/coral-embed-stream/src/Stream.js b/client/coral-embed-stream/src/Stream.js index 78a988553..74a1c7b65 100644 --- a/client/coral-embed-stream/src/Stream.js +++ b/client/coral-embed-stream/src/Stream.js @@ -1,8 +1,7 @@ import React, {PropTypes} from 'react'; import Comment from './Comment'; -const Stream = ({comments, currentUser, asset}) => { - console.log('currentUser', currentUser); +const Stream = ({comments, currentUser, asset, postAction, deleteAction, showSignInDialog}) => { return (
{ @@ -11,6 +10,9 @@ const Stream = ({comments, currentUser, asset}) => { depth={0} asset={asset} currentUser={currentUser} + postAction={postAction} + deleteAction={deleteAction} + showSignInDialog={showSignInDialog} key={comment.id} comment={comment} />; }) diff --git a/client/coral-embed-stream/src/graphql/mutations/deleteAction.graphql b/client/coral-embed-stream/src/graphql/mutations/deleteAction.graphql new file mode 100644 index 000000000..bfce8cf6a --- /dev/null +++ b/client/coral-embed-stream/src/graphql/mutations/deleteAction.graphql @@ -0,0 +1,3 @@ +mutation deleteAction ($id: ID!) { + deleteAction(id:$id) +} diff --git a/client/coral-embed-stream/src/graphql/mutations/index.js b/client/coral-embed-stream/src/graphql/mutations/index.js index 419891c06..d3c0a6080 100644 --- a/client/coral-embed-stream/src/graphql/mutations/index.js +++ b/client/coral-embed-stream/src/graphql/mutations/index.js @@ -1,5 +1,7 @@ import {graphql} from 'react-apollo'; import POST_COMMENT from './postComment.graphql'; +import POST_ACTION from './postAction.graphql'; +import DELETE_ACTION from './deleteAction.graphql'; export const postComment = graphql(POST_COMMENT, { props: ({mutate}) => ({ @@ -13,3 +15,25 @@ export const postComment = graphql(POST_COMMENT, { }); }}), }); + +export const postAction = graphql(POST_ACTION, { + props: ({mutate}) => ({ + postAction: (action) => { + return mutate({ + variables: { + action + } + }); + }}), +}); + +export const deleteAction = graphql(DELETE_ACTION, { + props: ({mutate}) => ({ + deleteAction: (id) => { + return mutate({ + variables: { + id + } + }); + }}), +}); diff --git a/client/coral-embed-stream/src/graphql/mutations/postAction.graphql b/client/coral-embed-stream/src/graphql/mutations/postAction.graphql index 52a0e1735..fff737fa8 100644 --- a/client/coral-embed-stream/src/graphql/mutations/postAction.graphql +++ b/client/coral-embed-stream/src/graphql/mutations/postAction.graphql @@ -1,5 +1,5 @@ -mutation CreateAction ($action: ActionInput) { +mutation CreateAction ($action: CreateActionInput!) { createAction(action:$action) { - ...action + id } } diff --git a/client/coral-embed-stream/src/graphql/queries/index.js b/client/coral-embed-stream/src/graphql/queries/index.js index 47f585449..ecf875aaa 100644 --- a/client/coral-embed-stream/src/graphql/queries/index.js +++ b/client/coral-embed-stream/src/graphql/queries/index.js @@ -3,7 +3,7 @@ import STREAM_QUERY from './streamQuery.graphql'; import Pym from 'pym.js'; const pym = new Pym.Child({polling: 100}); -let url = pym.parentUrl; +let url = pym.parentUrl || 'http://localhost:3000/'; export const queryStream = graphql(STREAM_QUERY, { options: {variables: {asset_url: url}} diff --git a/client/coral-plugin-likes/LikeButton.js b/client/coral-plugin-likes/LikeButton.js index fae30c8c7..796ad159c 100644 --- a/client/coral-plugin-likes/LikeButton.js +++ b/client/coral-plugin-likes/LikeButton.js @@ -4,33 +4,26 @@ import translations from './translations.json'; const name = 'coral-plugin-likes'; -const LikeButton = ({like, id, postAction, deleteAction, addItem, showSignInDialog, updateItem, currentUser, banned}) => { - const liked = like && like.current_user; +const LikeButton = ({like, id, postAction, deleteAction, showSignInDialog, currentUser}) => { + const liked = like && like.current; const onLikeClick = () => { if (!currentUser) { const offset = document.getElementById(`c_${id}`).getBoundingClientRect().top - 75; showSignInDialog(offset); return; } - if (banned) { + if (currentUser.banned) { return; } if (!liked) { - const action = { - action_type: 'like' - }; - postAction(id, 'comments', action) - .then((action) => { - let id = `${action.action_type}_${action.item_id}`; - addItem({id, current_user: action, count: like ? like.count + 1 : 1}, 'actions'); - updateItem(action.item_id, action.action_type, id, 'comments'); - }); + postAction({ + item_id: id, + item_type: 'COMMENTS', + action_type: 'LIKE' + }); + // TODO: frontend update from mutation } else { - deleteAction(liked.id) - .then(() => { - updateItem(like.id, 'count', like.count - 1, 'actions'); - updateItem(like.id, 'current_user', false, 'actions'); - }); + deleteAction(liked.id); } };