2016-11-11 18:29:49 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
2016-11-29 12:27:26 +01:00
|
|
|
import Posts from 'meteor/nova:posts';
|
2016-11-11 18:29:49 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
|
|
|
import { graphql } from 'react-apollo';
|
|
|
|
import gql from 'graphql-tag';
|
|
|
|
|
2016-11-22 18:39:50 -05:00
|
|
|
// 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);
|
|
|
|
}
|