| 409 | }) |
| 410 | } |
| 411 | unLike (comment) { |
| 412 | const { user } = this.state |
| 413 | let { comments } = this.state |
| 414 | |
| 415 | // const { user } = this.state |
| 416 | // let id |
| 417 | // comment.reactions.nodes.forEach(r => { |
| 418 | // if (r.user.login = user.login) id = r.databaseId |
| 419 | // }) |
| 420 | // return axiosGithub.delete(`/reactions/${id}`, { |
| 421 | // headers: { |
| 422 | // Authorization: `token ${this.accessToken}`, |
| 423 | // Accept: 'application/vnd.github.squirrel-girl-preview' |
| 424 | // } |
| 425 | // }).then(res => { |
| 426 | // console.log('res:', res) |
| 427 | // }) |
| 428 | |
| 429 | const getQL = id => ({ |
| 430 | operationName: 'RemoveReaction', |
| 431 | query: ` |
| 432 | mutation RemoveReaction{ |
| 433 | removeReaction (input:{ |
| 434 | subjectId: "${id}", |
| 435 | content: HEART |
| 436 | }) { |
| 437 | reaction { |
| 438 | content |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | ` |
| 443 | }) |
| 444 | |
| 445 | axiosGithub.post('/graphql', getQL(comment.gId), { |
| 446 | headers: { |
| 447 | Authorization: `bearer ${this.accessToken}` |
| 448 | } |
| 449 | }).then(res => { |
| 450 | if (res.data) { |
| 451 | comments = comments.map(c => { |
| 452 | if (c.id === comment.id) { |
| 453 | const index = c.reactions.nodes.findIndex(n => n.user.login === user.login) |
| 454 | if (~index) { |
| 455 | c.reactions.totalCount -= 1 |
| 456 | c.reactions.nodes.splice(index, 1) |
| 457 | } |
| 458 | c.reactions.viewerHasReacted = false |
| 459 | return Object.assign({}, c) |
| 460 | } |
| 461 | return c |
| 462 | }) |
| 463 | |
| 464 | this.setState({ |
| 465 | comments |
| 466 | }) |
| 467 | } |
| 468 | }) |