@@ -23,26 +23,31 @@ class StateSortedSchools extends Component {
2323 }
2424
2525 onSearchChange = ( value ) => {
26- // const regex = new RegExp (value, 'gi');
27- // const arr = this.state.by_state.match(regex);
28- // this.setState({ stateList: arr });
29- this . setState ( { query : value } ) ;
30- this . setState ( { schoolsByState : this . searchState ( value ) } ) ;
26+ if ( value . length > 1 ) {
27+ // Prevent query with just one character in search field
28+ this . setState ( { query : value } ) ;
29+ this . setState ( { schoolsByState : this . searchState ( value ) } ) ;
30+ }
3131 }
3232
3333 searchState = ( string ) => {
34- const stringFormat = string . replace ( / \w \S * / g, txt => txt . charAt ( 0 ) . toUpperCase ( ) + txt . substr ( 1 ) . toLowerCase ( ) ) ;
34+ const stringFormat = string . replace ( / \w \S * / g, txt =>
35+ txt . charAt ( 0 ) . toUpperCase ( ) + txt . substr ( 1 ) . toLowerCase ( )
36+ ) ;
3537 const schools = [ ] ;
38+
3639 this . state . schools . forEach ( ( school ) => {
37- const locations = school . locations . filter ( location =>
38- location . state === stringFormat
39- ) ;
40+ // Search non-online locations for input per key stroke
41+ const locations = school . locations . filter ( location => location . state !== undefined )
42+ . filter ( location => location . state . includes ( stringFormat ) ) ;
43+
4044 if ( locations . length > 0 ) {
4145 const newSchool = Object . assign ( { } , school ) ;
4246 newSchool . locations = locations ;
4347 schools . push ( newSchool ) ;
4448 }
4549 } ) ;
50+
4651 return schools ;
4752 }
4853
@@ -62,7 +67,8 @@ class StateSortedSchools extends Component {
6267 hardware = { school . hardware_included ? 'Yes' : 'No' }
6368 />
6469 )
65- ) ;
70+ ) ;
71+
6672 return (
6773 < Section
6874 id = "schoolsByState"
@@ -76,7 +82,7 @@ class StateSortedSchools extends Component {
7682 onChange = { this . onSearchChange }
7783 id = "search"
7884 />
79- < div className = { styles . stateSchool } >
85+ < div className = { styles . stateSchools } >
8086 { stateSchools }
8187 </ div >
8288 </ Section >
0 commit comments