@@ -3,9 +3,9 @@ import Section from 'shared/components/section/section';
33import SchoolCard from 'shared/components/schoolCard/schoolCard' ;
44import FormInput from 'shared/components/form/formInput/formInput' ;
55import styles from './stateSortedSchools.css' ;
6+ import stateCodes from '../stateCodes.json' ;
67
7- const endpoint = 'https://raw.githubusercontent.com/OperationCode/operationcode_frontend/code-schools-cooper-kyle/src/scenes/home/codeSchools/schools.json' ;
8- const gettingSchoolData = fetch ( endpoint )
8+ const gettingSchoolData = fetch ( 'https://api.operationcode.org/api/v1/code_schools.json' )
99 . then ( response => response . json ( ) ) ;
1010
1111class StateSortedSchools extends Component {
@@ -35,15 +35,18 @@ class StateSortedSchools extends Component {
3535 }
3636
3737 searchState = ( string ) => {
38- const stringFormat = string . replace ( / \w \S * / g, txt =>
39- txt . charAt ( 0 ) . toUpperCase ( ) + txt . substr ( 1 ) . toLowerCase ( )
40- ) ;
38+ const userInput = string . replace ( / \w \S * / g, txt => txt . toUpperCase ( ) ) ;
4139 const schools = [ ] ;
4240
41+ // Return true if input matches state code or name (ex: "CA or California")
42+ function matchesState ( school , input ) {
43+ const stateName = stateCodes [ school . state ] . toUpperCase ( ) ;
44+ console . log ( stateName ) ;
45+ return school . state . includes ( input ) || stateName . includes ( input ) ;
46+ }
47+
4348 this . state . schools . forEach ( ( school ) => {
44- // Search non-online locations for input per key stroke
45- const locations = school . locations . filter ( location => location . state !== undefined )
46- . filter ( location => location . state . includes ( stringFormat ) ) ;
49+ const locations = school . locations . filter ( location => matchesState ( location , userInput ) ) ;
4750
4851 if ( locations . length > 0 ) {
4952 const newSchool = Object . assign ( { } , school ) ;
@@ -53,7 +56,7 @@ class StateSortedSchools extends Component {
5356 } ) ;
5457
5558 return schools ;
56- }
59+ } ;
5760
5861 render ( ) {
5962 const stateSchools = ! this . state . schoolsByState ? null : this . state . schoolsByState
0 commit comments