@@ -2,35 +2,26 @@ import React, { Component } from 'react';
2
2
import axios from 'axios' ;
3
3
4
4
import { Button , Input , Fa } from 'mdbreact' ;
5
- import { Card , CardBody , CardTitle , CardText } from 'mdbreact' ;
5
+ import { Card , CardBody , CardTitle , CardText , ToastContainer , toast } from 'mdbreact' ;
6
6
7
7
export default class SearchBar extends Component {
8
8
constructor ( props ) {
9
9
super ( props )
10
10
11
11
this . state = {
12
12
userName : '' ,
13
- reposData : [ ]
13
+ reposData : [ ] ,
14
+ userData : [ ] ,
15
+ searchButton : 'Search' ,
14
16
}
17
+
15
18
}
16
-
17
19
handleChange = ( e ) => {
18
20
this . setState ( {
19
21
userName : e . target . value
20
22
} )
21
23
}
22
24
23
- handleSubmit = ( e ) => {
24
- console . log ( "Submitted" ) ;
25
- axios . get ( 'https://api.github.com/users/' + this . state . userName + '/repos' )
26
- . then ( ( response ) => {
27
- console . log ( response . data ) ;
28
-
29
- this . setState ( {
30
- reposData : response . data
31
- } )
32
- } )
33
- }
34
25
35
26
onKeyDown = ( e ) => {
36
27
if ( e . keyCode === 13 && e . shiftKey === false ) {
@@ -39,16 +30,47 @@ export default class SearchBar extends Component {
39
30
}
40
31
}
41
32
33
+ handleSubmit = ( e ) => {
34
+ console . log ( "Submitted" ) ;
35
+ if ( this . state . userName === '' ) {
36
+ toast . warn ( 'Please enter a username' ) ;
37
+ return ;
38
+ }
39
+ this . setState ( {
40
+ searchButton : 'Searching...'
41
+ } ) ;
42
+ let getData = [ ] ;
43
+ getData . push ( axios . get ( 'https://api.github.com/users/' + this . state . userName + '/repos' ) ) ;
44
+ getData . push ( axios . get ( 'https://api.github.com/users/' + this . state . userName ) ) ;
45
+
46
+ Promise . all ( getData )
47
+ . then ( result => {
48
+ this . setState ( {
49
+ reposData : result [ 0 ] . data ,
50
+ userData : result [ 1 ] . data ,
51
+ searchButton : 'Search'
52
+ } ) ;
53
+ console . log ( this . state )
54
+ } ) ;
55
+ }
56
+
42
57
render ( ) {
43
58
return (
44
59
< div >
45
- < Input label = "Type any Github Username" onKeyDown = { this . onKeyDown } onChange = { this . handleChange } group type = "text" />
60
+ < Input label = "Type any Github Username" onKeyDown = { this . onKeyDown } onChange = { this . handleChange } group type = "text" />
46
61
{ /* <Input label="Type your password" icon="lock" group type="password" /> */ }
47
- < Button color = "danger" onClick = { this . handleSubmit } > Search < Fa icon = "search" /> </ Button >
62
+ < Avatar
63
+ data = { this . state . userData }
64
+ />
65
+ < Button color = "danger" onClick = { this . handleSubmit } > { this . state . searchButton } < Fa icon = "search" /> </ Button >
48
66
< PanelBoard
49
67
data = { this . state . reposData }
50
68
/>
51
-
69
+ < ToastContainer
70
+ hideProgressBar = { true }
71
+ newestOnTop = { true }
72
+ autoClose = { 2000 }
73
+ />
52
74
</ div >
53
75
54
76
) ;
@@ -71,6 +93,7 @@ class PanelBoard extends Component {
71
93
branch = { repo . default_branch }
72
94
dLink = { repo . html_url }
73
95
/>
96
+ // console.log(repo.name)
74
97
) ) ;
75
98
76
99
return (
@@ -115,4 +138,18 @@ class ResultPanel extends Component {
115
138
) ;
116
139
}
117
140
}
141
+
142
+ class Avatar extends Component {
143
+ render ( ) {
144
+ const avatar = this . props . data ? this . props . data : null ;
145
+
146
+ return (
147
+ avatar &&
148
+ < div >
149
+ < img className = "gitAvatar" src = { avatar . avatar_url } />
150
+ < div > < strong > { avatar . name } </ strong > </ div >
151
+ </ div >
152
+ ) ;
153
+ }
154
+ }
118
155
// export default Timer;
0 commit comments