Created
November 6, 2017 19:26
-
-
Save janpauldahlke/ff71d23755fa08ccb092bf9294d14f7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react'; | |
import {graphql, compose} from 'react-apollo'; | |
import addLike from '../queries/addLikes.js'; | |
import removeLike from '../queries/removeLikes.js'; | |
import getSongQuery from '../queries/fetchSongByID'; | |
class Likes extends Component { | |
onAddLikeClick(){ | |
this.props.addLikesToGivenLyric({ | |
variables: { | |
lyricId: this.props.lyricId | |
}, | |
refetchQueries: [{query: getSongQuery, variables: {songId: this.props.songId}}] | |
}) | |
} | |
onRemoveLikeClick(){ | |
this.props.removeLikesFromGivenLyric({ | |
variables: { | |
lyricId: this.props.lyricId | |
}, | |
refetchQueries: [{query: getSongQuery, variables: {songId: this.props.songId}}] | |
}) | |
} | |
//------------------- | |
render(){ | |
console.log('likesProps', this.props) | |
return( | |
<div className="row"> | |
<div className="col-4 card text-center">{this.props.likes} Likes</div> | |
<div className="col-4 btn btn-sm btn-success" | |
onClick={this.onAddLikeClick.bind(this)} | |
>upvote</div> | |
<div className="col-4 btn btn-sm btn-warning" | |
onClick={this.onRemoveLikeClick.bind(this)} | |
>downvote</div> | |
</div> | |
); | |
} | |
} | |
const LikesWithMutations = compose( | |
graphql(addLike, {name: 'addLikesToGivenLyric'}), | |
graphql(removeLike, {name: 'removeLikesFromGivenLyric'}) | |
)(Likes) | |
export default LikesWithMutations; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment