@@ -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-
6+ import stateCodes from '../stateCodes.json' ;
77
88const gettingSchoolData = fetch ( 'https://api.operationcode.org/api/v1/code_schools.json' )
99 . then ( response => response . json ( ) ) ;
@@ -35,22 +35,36 @@ class StateSortedSchools extends Component {
3535 }
3636
3737 searchState = ( string ) => {
38- const stringFormat = string . replace ( / \w \S * / g, txt => txt . toUpperCase ( ) ) ;
38+ const userInput = 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+
4047 this . state . schools . forEach ( ( school ) => {
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+ for ( location of school . locations . filter ( _school => matchesState ( _school , userInput ) ) ) {
49+ schools . push ( {
50+ name : school . name ,
51+ url : school . url ,
52+ address : school . location . address1 ,
53+ city : school . location . city ,
54+ state : school . location . state ,
55+ zip : school . location . zip ,
56+ va_accepted : school . location . va_accepted ,
57+ full_time : school . full_time ,
58+ hardware_included : school . hardware_included
59+ } ) ;
4860 }
4961 } ) ;
62+
5063 return schools ;
51- }
64+ } ;
5265
5366 render ( ) {
67+ console . log ( this . state . schoolsByState ) ;
5468 const stateSchools = ! this . state . schoolsByState ? null : this . state . schoolsByState
5569 . map ( school =>
5670 (
@@ -59,12 +73,11 @@ class StateSortedSchools extends Component {
5973 alt = { school . name }
6074 schoolName = { school . name }
6175 link = { school . url }
62- schoolAddress = { school . locations [ 0 ] . address1 }
63- schoolCity = { school . locations [ 0 ] . city }
64- schoolState = { school . locations [ 0 ] . state }
76+ schoolAddress = { school . address }
77+ schoolCity = { school . city }
78+ schoolState = { school . state }
6579 logo = { school . logo }
66- GI = { 'Yes' }
67- // GI={school.locations[0].va_accepted ? 'Yes' : 'No'}
80+ GI = { school . va_accepted ? 'Yes' : 'No' }
6881 fullTime = { school . full_time ? 'Full-Time' : 'Flexible' }
6982 hardware = { school . hardware_included ? 'Yes' : 'No' }
7083 />
0 commit comments