@@ -3,7 +3,7 @@ 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' ;
6+
77
88const gettingSchoolData = fetch ( 'https://api.operationcode.org/api/v1/code_schools.json' )
99 . then ( response => response . json ( ) ) ;
@@ -35,24 +35,22 @@ class StateSortedSchools extends Component {
3535 }
3636
3737 searchState = ( string ) => {
38- const userInput = string . replace ( / \w \S * / g, txt => txt . toUpperCase ( ) ) ;
38+ const stringFormat = string . replace ( / \w \S * / g, txt => txt . toUpperCase ( ) ) ;
3939 const schools = [ ] ;
40-
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- return school . state . includes ( input ) || stateName . includes ( input ) ;
45- }
46-
4740 this . state . schools . forEach ( ( school ) => {
48- schools . push ( school . locations . filter ( location => matchesState ( location , userInput ) ) ) ;
41+ const locations = school . locations . filter ( location =>
42+ location . state === stringFormat
43+ ) ;
44+ if ( locations . length > 0 ) {
45+ const newSchool = Object . assign ( { } , school ) ;
46+ newSchool . locations = locations ;
47+ schools . push ( newSchool ) ;
48+ }
4949 } ) ;
50-
5150 return schools ;
52- } ;
51+ }
5352
5453 render ( ) {
55- console . log ( this . state . schoolsByState ) ;
5654 const stateSchools = ! this . state . schoolsByState ? null : this . state . schoolsByState
5755 . map ( school =>
5856 (
@@ -61,9 +59,9 @@ class StateSortedSchools extends Component {
6159 alt = { school . name }
6260 schoolName = { school . name }
6361 link = { school . url }
64- schoolAddress = { ' school.locations[0].address1' }
65- schoolCity = { ' school.locations[0].city' }
66- schoolState = { ' school.locations[0].state' }
62+ schoolAddress = { school . locations [ 0 ] . address1 }
63+ schoolCity = { school . locations [ 0 ] . city }
64+ schoolState = { school . locations [ 0 ] . state }
6765 logo = { school . logo }
6866 GI = { 'Yes' }
6967 // GI={school.locations[0].va_accepted ? 'Yes' : 'No'}
0 commit comments