-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
75 lines (69 loc) · 2.05 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from 'react';
import ReactDOM from 'react-dom';
import SearchUsers from'./SearchUsers';
import Profile from'./Profile';
import api from './githubApi';
class App extends React.Component {
constructor() {
super();
this.state = {
users:[],
username: null,
user: {}
};
this.updateUsers = this.updateUsers.bind(this);
this.onUserClick = this.onUserClick.bind(this);
// default profile
this.fetchProfile('klode');
}
updateUsers(users) {
console.log('in update', users);
this.setState({
users: users
});
}
onUserClick(user) {
console.log('onUserClick', user);
this.fetchProfile(user.login);
this.setState({
username: user.login
});
}
fetchProfile(username) {
console.log('fetchProfile', username);
if(!username) {
return;
}
api.getUser(username)
.then((data) => {
console.log('getUser', data);
this.setState({
user: data
});
})
.catch((error) => console.log('Oops! . There Is A Problem') );
}
render(){
//let username = this.state.users && this.state.users[0] ? this.state.users[0].login : null;
console.log('App.render');
return (
<div className="mdl-grid">
<div className="search-users mdl-cell mdl-cell--4-col mdl-shadow--2dp">
<div className="header">
<span className="mdl-layout-title">Find GitHub Users</span>
<div className="mdl-layout-spacer"></div>
</div>
<SearchUsers
onSearch={this.updateUsers}
onUserClick={this.onUserClick}
users={this.state.users}
activeUserId={this.state.user.id}/>
</div>
<div className="mdl-cell mdl-cell--8-col">
<Profile user={this.state.user}/>
</div>
</div>
)
}
}
export default App