11import React , { Component , PropTypes } from 'react' ;
2- import { Input , Button } from 'react-bootstrap' ;
2+ import { FormGroup , ControlLabel , FormControl , Button } from 'react-bootstrap' ;
33import { AutoAffix } from 'react-overlays' ;
44
55class SearchForm extends Component {
66 constructor ( props ) {
77 super ( props ) ;
88
9- this . handleClick = this . handleClick . bind ( this ) ;
9+ this . state = {
10+ repository : '' ,
11+ language : '' ,
12+ } ;
13+ this . handleRepositoryChange = this . handleRepositoryChange . bind ( this ) ;
14+ this . handleLanguageChange = this . handleLanguageChange . bind ( this ) ;
15+ this . handleSubmitClick = this . handleSubmitClick . bind ( this ) ;
1016 }
1117
12- handleClick ( ) {
13- const repositoryValue = this . refs . repository . getValue ( ) ;
14- const languageValue = this . refs . language . getValue ( ) ;
15- if ( repositoryValue ) {
16- if ( languageValue !== 'undefined' ) {
17- this . props . search ( repositoryValue , languageValue ) ;
18+ handleRepositoryChange ( e ) {
19+ this . setState ( { repository : e . target . value } ) ;
20+ }
21+
22+ handleLanguageChange ( e ) {
23+ this . setState ( { language : e . target . value } ) ;
24+ }
25+
26+ handleSubmitClick ( ) {
27+ const { repository, language} = this . state ;
28+ if ( repository ) {
29+ if ( language ) {
30+ this . props . search ( repository , language ) ;
1831 } else {
19- this . props . search ( repositoryValue ) ;
32+ this . props . search ( repository ) ;
2033 }
2134 }
2235 }
@@ -25,21 +38,30 @@ class SearchForm extends Component {
2538 return (
2639 < AutoAffix viewportOffsetTop = { 55 } >
2740 < div >
28- < Input
29- type = "text"
30- ref = "repository"
31- label = "Enter a keyword to search Github"
32- placeholder = "search term"
33- />
34- < Input type = "select" ref = "language" label = "Optianally select a language" >
35- < option value = "undefined" > Select a language</ option >
36- < option value = "javascript" > JavaScript</ option >
37- < option value = "csharp" > C#</ option >
38- < option value = "python" > Python</ option >
39- < option value = "ruby" > Ruby</ option >
40- < option value = "java" > Java</ option >
41- </ Input >
42- < Button bsStyle = "primary" onClick = { this . handleClick } > Search</ Button >
41+ < FormGroup controlId = "repositorySearch" >
42+ < ControlLabel > Enter a keyword to search Github</ ControlLabel >
43+ < FormControl
44+ type = "text"
45+ value = { this . state . repository }
46+ onChange = { this . handleRepositoryChange }
47+ placeholder = "search term"
48+ />
49+ </ FormGroup >
50+ < FormGroup controlId = "formControlsSelect" >
51+ < ControlLabel > Optianally select a programming language</ ControlLabel >
52+ < FormControl
53+ componentClass = "select"
54+ onChange = { this . handleLanguageChange }
55+ placeholder = "Select a programming language" >
56+ < option value = "undefined" > Select a language</ option >
57+ < option value = "javascript" > JavaScript</ option >
58+ < option value = "csharp" > C#</ option >
59+ < option value = "python" > Python</ option >
60+ < option value = "ruby" > Ruby</ option >
61+ < option value = "java" > Java</ option >
62+ </ FormControl >
63+ </ FormGroup >
64+ < Button bsStyle = "primary" onClick = { this . handleSubmitClick } > Search</ Button >
4365 </ div >
4466 </ AutoAffix >
4567 ) ;
0 commit comments