1
1
import React from 'react'
2
2
import Loading from '../Components/Loading' ;
3
3
import ProjectListSelector from '../Components/ProjectListSelector' ;
4
- import { withGithubRepositories } from './withGitHubRepositories' ;
4
+ import { withGithubRepositories , fetchGitHub } from './withGitHubRepositories' ;
5
5
import LABELS_TO_ADD from '../Labels' ;
6
6
import invertColor from '../invertColor' ;
7
7
import './GitHub.css' ;
@@ -13,12 +13,31 @@ class GitHub extends React.Component {
13
13
this . state = {
14
14
selectedOption : null ,
15
15
applying : false ,
16
+ applyedLabels : [ ]
16
17
}
17
18
}
18
19
19
20
handleApply ( selectedOption ) {
20
- console . log ( selectedOption )
21
21
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
+ } ) )
22
41
}
23
42
24
43
render ( ) {
@@ -53,7 +72,7 @@ class GitHub extends React.Component {
53
72
< label alt = { name } className = "label-item"
54
73
style = { { backgroundColor : '#' + color , color : invertColor ( '#' + color , true ) } }
55
74
>
56
- < input disabled type = "checkbox" />
75
+ < input disabled type = "checkbox" checked = { this . state . applyedLabels . indexOf ( name ) > - 1 } />
57
76
{ name }
58
77
</ label >
59
78
</ div >
0 commit comments