11import React from 'react'
22import Loading from '../Components/Loading' ;
33import ProjectListSelector from '../Components/ProjectListSelector' ;
4- import { withGithubRepositories } from './withGitHubRepositories' ;
4+ import { withGithubRepositories , fetchGitHub } from './withGitHubRepositories' ;
55import LABELS_TO_ADD from '../Labels' ;
66import invertColor from '../invertColor' ;
77import './GitHub.css' ;
@@ -13,12 +13,31 @@ class GitHub extends React.Component {
1313 this . state = {
1414 selectedOption : null ,
1515 applying : false ,
16+ applyedLabels : [ ]
1617 }
1718 }
1819
1920 handleApply ( selectedOption ) {
20- console . log ( selectedOption )
2121 this . setState ( { selectedOption, applying : true } )
22+ this . applyChangesToRepository ( selectedOption . value )
23+ }
24+
25+ async applyChangesToRepository ( repoName ) {
26+
27+ const createLabelsPromices = LABELS_TO_ADD . map ( l => this . createLabel ( repoName , l ) )
28+
29+ }
30+
31+ async createLabel ( repoName , { name, color } ) {
32+ fetchGitHub (
33+ `https://api.github.com/repos/${ repoName } /labels` ,
34+ 'POST' ,
35+ { name, color }
36+ )
37+
38+ this . setState ( ( { applyedLabels } ) => ( {
39+ applyedLabels : [ ...applyedLabels , name ]
40+ } ) )
2241 }
2342
2443 render ( ) {
@@ -53,7 +72,7 @@ class GitHub extends React.Component {
5372 < label alt = { name } className = "label-item"
5473 style = { { backgroundColor : '#' + color , color : invertColor ( '#' + color , true ) } }
5574 >
56- < input disabled type = "checkbox" />
75+ < input disabled type = "checkbox" checked = { this . state . applyedLabels . indexOf ( name ) > - 1 } />
5776 { name }
5877 </ label >
5978 </ div >
0 commit comments