-
Notifications
You must be signed in to change notification settings - Fork 28
/
GithubUser.js
51 lines (44 loc) · 1.62 KB
/
GithubUser.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
import React from 'react';
import Profile from '../../components/Profile/Profile.js';
import Repos from '../../components/Repos/Repos.js';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { getRepositories, getProfile, initUsername } from '../../redux/modules/singleUser.js';// import action creators
class GithubUser extends React.Component {
static propTypes = {
params: React.PropTypes.object.isRequired,
singleUser: React.PropTypes.object.isRequired,
initUsername: React.PropTypes.func.isRequired,
getProfile: React.PropTypes.func.isRequired,
getRepositories: React.PropTypes.func.isRequired
}
constructor(props) {
super(props);
// init context bindings - due to diff between React.createClass and ES6 class
this.reposGotoPage = this.reposGotoPage.bind(this);
this.componentWillMount = this.componentWillMount.bind(this);
}
componentWillMount() {
this.props.initUsername(this.props.params.username);
this.props.getProfile(this.props.params.username);
this.props.getRepositories(this.props.params.username);
}
reposGotoPage(pageNum) {
this.props.getRepositories(this.props.params.username, {
page: pageNum
});
}
render() {
const { profile, repositories } = this.props.singleUser;
return (
<div>
<Profile profile={profile}/>
<Repos repositories={repositories} reposGotoPage={this.reposGotoPage}/>
</div>
);
}
}
export default connect(
(state) => ({ singleUser: state.singleUser }),
(dispatch) => bindActionCreators({ getRepositories, getProfile, initUsername }, dispatch)
)(GithubUser);