-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
71 lines (58 loc) · 1.56 KB
/
index.js
File metadata and controls
71 lines (58 loc) · 1.56 KB
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
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { searchRepo } from '../../actions'
import ReposList from '../../components/reposList';
import styles from './styles.css';
class PageSearch extends Component {
constructor(props) {
super(props);
this.state = {
query: ''
};
}
onInputChange(event) {
this.setState({
query: event.target.value
});
}
onFormSubmit(event) {
event.preventDefault();
this.props.searchRepo(this.state.query);
this.setState({ query: '' });
}
renderResults() {
if (this.props.repos.length > 0) {
return (
<div className={styles.results}>
<ReposList repos={this.props.repos} />
</div>
);
}
}
render() {
return (
<div className="jumbotron">
<form onSubmit={this.onFormSubmit.bind(this)} className="input-group">
<input
placeholder="Github Search"
className="form-control"
value={this.state.query}
onChange={this.onInputChange.bind(this)}
/>
<span className="input-group-btn">
<button type="submit" className="btn btn-secondary">Submit</button>
</span>
</form>
{this.renderResults()}
</div>
);
}
}
function mapDispatchToProps(dispatch) {
return bindActionCreators({ searchRepo }, dispatch)
};
function mapStateToProps({ repos }) {
return { repos };
};
export default connect(mapStateToProps, mapDispatchToProps)(PageSearch)