Vulcan/packages/nova-voting/lib/containers/withVote.js

39 lines
1 KiB
JavaScript
Raw Normal View History

2016-11-11 18:29:49 +09:00
import Telescope from 'meteor/nova:lib';
import React, { PropTypes, Component } from 'react';
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
// to adapt like withNew? or withSingle?
export default function withVote(component) {
2016-11-11 18:29:49 +09:00
return graphql(gql`
mutation postsVote($documentId: String, $voteType: String) {
postsVote(documentId: $documentId, voteType: $voteType) {
_id
baseScore
downvotes
downvoters {
_id
}
upvotes
upvoters {
_id
}
}
}
`, {
props: ({ownProps, mutate}) => ({
vote: ({post, voteType, currentUser}) => {
const votedItem = Telescope.operateOnItem(Posts, post, currentUser, voteType, true);
return mutate({
variables: {documentId: post._id, voteType},
optimisticResponse: {
__typename: 'Mutation',
postsVote: {
...votedItem,
},
}
})
}
}),
})(component);
}