Created
November 6, 2017 19:07
-
-
Save janpauldahlke/f9999fb1e682268725686afd8bb9e3ce to your computer and use it in GitHub Desktop.
This file contains hidden or 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} 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(){ | |
console.log('onAdd') | |
this.props.mutate({ | |
variables: { | |
lyricId: this.props.lyricId | |
}, | |
refetchQueries: [{query: getSongQuery, variables: {songId: this.props.songId}}] | |
}) | |
} | |
onRemoveLikeClick(){ | |
console.log('onRemove') | |
this.props.mutate({ | |
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> | |
); | |
} | |
} | |
export default graphql(removeLike)( | |
graphql(addLike)( | |
graphql(getSongQuery)(Likes) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment