File tree Expand file tree Collapse file tree 4 files changed +88
-11
lines changed Expand file tree Collapse file tree 4 files changed +88
-11
lines changed Original file line number Diff line number Diff line change 38
38
"react-dom" : " ^16.2.0" ,
39
39
"react-router" : " ^4.2.0" ,
40
40
"react-router-dom" : " ^4.2.2" ,
41
+ "react-select" : " ^1.2.1" ,
41
42
"reactstrap" : " ^5.0.0-beta" ,
42
43
"style-loader" : " 0.19.0" ,
43
44
"svg-react-loader" : " ^0.4.5" ,
49
50
"whatwg-fetch" : " 2.0.3"
50
51
},
51
52
"scripts" : {
52
- "start" : " yarn install && HOST=cwps.lucassabreu.test node scripts/start.js" ,
53
+ "start" : " yarn install && node scripts/start.js" ,
53
54
"build" : " node scripts/build.js && cp _redirects build/_redirects" ,
54
55
"test" : " node scripts/test.js --env=jsdom"
55
56
},
Original file line number Diff line number Diff line change 1
1
import React from 'react'
2
2
import Loading from '../Components/Loading' ;
3
+ import { withGithubRepositories } from './withGitHubRepositories' ;
4
+ import Select from 'react-select' ;
5
+ import 'react-select/dist/react-select.css' ;
3
6
4
7
class GitHub extends React . Component {
5
- constructor ( props ) {
6
- super ( props ) ;
7
8
8
- const params = new URLSearchParams ( props . location . search ) ;
9
+ constructor ( props ) {
10
+ super ( props )
11
+ this . state = { selectedOption : null }
12
+ }
9
13
10
- this . state = {
11
- loading : true ,
12
- code : params . get ( 'code' )
13
- } ;
14
+ handleSelect ( selectedOption ) {
15
+ this . setState ( { selectedOption } )
14
16
}
15
17
16
18
render ( ) {
17
- const { loading } = this . state ;
19
+ const { loading, repositories } = this . props ;
20
+ const selectedOption = this . state . selectedOption && this . state . selectedOption . value
21
+
22
+ repositories . sort ( ( a , b ) => a . full_name . toLocaleLowerCase ( ) > b . full_name . toLocaleLowerCase ( ) ? 1 : - 1 )
18
23
return (
19
24
< div className = "GitHub" >
20
25
{ loading ?
@@ -24,11 +29,19 @@ class GitHub extends React.Component {
24
29
</ section >
25
30
:
26
31
< section >
32
+ < Select
33
+ value = { selectedOption }
34
+ onChange = { ( e ) => this . handleSelect ( e ) }
35
+ options = { repositories . map ( r => Object . assign ( r , {
36
+ value : r . full_name ,
37
+ label : r . full_name ,
38
+ } ) ) }
39
+ />
27
40
</ section >
28
41
}
29
42
</ div >
30
43
)
31
44
}
32
45
}
33
46
34
- export default GitHub
47
+ export default withGithubRepositories ( GitHub )
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+
3
+ export function withGithubRepositories ( Component ) {
4
+ return class extends React . Component {
5
+ constructor ( props ) {
6
+ super ( props ) ;
7
+ this . state = {
8
+ loading : true ,
9
+ repositories : [ ] ,
10
+ }
11
+ }
12
+
13
+ async componentDidMount ( ) {
14
+ const repositories = await this . fetchNextPage ( ) ;
15
+ this . setState ( {
16
+ loading : false ,
17
+ repositories : repositories ,
18
+ } )
19
+ }
20
+
21
+ async fetchNextPage ( page ) {
22
+ const paging = page ? `?page=${ page } ` : '' ;
23
+
24
+ const resp = await fetch ( new Request (
25
+ `https://api.github.com/user/repos${ paging } ` ,
26
+ {
27
+ headers : new Headers ( {
28
+ Authorization : `token ${ sessionStorage . getItem ( 'github-token' ) } ` ,
29
+ Accept : 'application/json' ,
30
+ } )
31
+ }
32
+ ) ) ;
33
+
34
+ let repos = await resp . json ( ) ;
35
+ if ( repos . length === 0 ) {
36
+ return repos ;
37
+ }
38
+
39
+ return repos . concat ( await this . fetchNextPage ( page ? page + 1 : 2 ) ) ;
40
+ }
41
+
42
+ render ( ) {
43
+ return < Component { ...this . props }
44
+ loading = { this . state . loading }
45
+ repositories = { this . state . repositories }
46
+ />
47
+ }
48
+ }
49
+ }
Original file line number Diff line number Diff line change @@ -1331,7 +1331,7 @@ clap@^1.0.9:
1331
1331
dependencies :
1332
1332
chalk "^1.1.3"
1333
1333
1334
- classnames@^2.2.3, classnames@^2.2.5 :
1334
+ classnames@^2.2.3, classnames@^2.2.4, classnames@^2.2. 5 :
1335
1335
version "2.2.5"
1336
1336
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.5.tgz#fb3801d453467649ef3603c7d61a02bd129bde6d"
1337
1337
@@ -5210,6 +5210,12 @@ react-error-overlay@^4.0.0:
5210
5210
version "4.0.0"
5211
5211
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-4.0.0.tgz#d198408a85b4070937a98667f500c832f86bd5d4"
5212
5212
5213
+ react-input-autosize@^2.1.2 :
5214
+ version "2.2.1"
5215
+ resolved "https://registry.yarnpkg.com/react-input-autosize/-/react-input-autosize-2.2.1.tgz#ec428fa15b1592994fb5f9aa15bb1eb6baf420f8"
5216
+ dependencies :
5217
+ prop-types "^15.5.8"
5218
+
5213
5219
react-popper@^0.7.2 :
5214
5220
version "0.7.5"
5215
5221
resolved "https://registry.yarnpkg.com/react-popper/-/react-popper-0.7.5.tgz#71c25946f291db381231281f6b95729e8b801596"
@@ -5240,6 +5246,14 @@ react-router@^4.2.0:
5240
5246
prop-types "^15.5.4"
5241
5247
warning "^3.0.0"
5242
5248
5249
+ react-select@^1.2.1 :
5250
+ version "1.2.1"
5251
+ resolved "https://registry.yarnpkg.com/react-select/-/react-select-1.2.1.tgz#a2fe58a569eb14dcaa6543816260b97e538120d1"
5252
+ dependencies :
5253
+ classnames "^2.2.4"
5254
+ prop-types "^15.5.8"
5255
+ react-input-autosize "^2.1.2"
5256
+
5243
5257
react-transition-group@^2.2.0 :
5244
5258
version "2.2.1"
5245
5259
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-2.2.1.tgz#e9fb677b79e6455fd391b03823afe84849df4a10"
You can’t perform that action at this time.
0 commit comments