11import React , { Component } from 'react' ;
22import Section from 'shared/components/section/section' ;
3+ import SchoolCard from 'shared/components/schoolCard/schoolCard' ;
34import FormInput from 'shared/components/form/formInput/formInput' ;
4- // import styles from './stateSortedSchools.css';
5+ import styles from './stateSortedSchools.css' ;
56
67const endpoint = 'https://raw.githubusercontent.com/OperationCode/operationcode_frontend/code-schools-cooper-kyle/src/scenes/home/codeSchools/schools.json' ;
78const gettingSchoolData = fetch ( endpoint )
@@ -12,23 +13,56 @@ class StateSortedSchools extends Component {
1213 super ( props ) ;
1314 this . state = {
1415 query : null ,
15- stateList : null ,
16- by_state : null
16+ schoolsByState : null ,
17+ schools : null
1718 } ;
1819
1920 gettingSchoolData . then ( data =>
20- this . setState ( { by_state : data . by_state } )
21+ this . setState ( { schools : data } )
2122 ) ;
2223 }
2324
2425 onSearchChange = ( value ) => {
25- const regex = new RegExp ( value , 'gi' ) ;
26- const arr = this . state . by_state . match ( regex ) ;
27- this . setState ( { stateList : arr } ) ;
26+ // const regex = new RegExp(value, 'gi');
27+ // const arr = this.state.by_state.match(regex);
28+ // this.setState({ stateList: arr });
2829 this . setState ( { query : value } ) ;
30+ this . setState ( { schoolsByState : this . searchState ( value ) } ) ;
31+ }
32+
33+ searchState = ( string ) => {
34+ const stringFormat = string . replace ( / \w \S * / g, txt => txt . charAt ( 0 ) . toUpperCase ( ) + txt . substr ( 1 ) . toLowerCase ( ) ) ;
35+ const schools = [ ] ;
36+ this . state . schools . forEach ( ( School ) => {
37+ const locations = School . locations . filter ( location =>
38+ location . state === stringFormat
39+ ) ;
40+ if ( locations . length > 0 ) {
41+ const newSchool = Object . assign ( { } , School ) ;
42+ newSchool . locations = locations ;
43+ schools . push ( newSchool ) ;
44+ }
45+ } ) ;
46+ this . setState ( { schoolsByState : schools } ) ;
2947 }
3048
3149 render ( ) {
50+ const stateSchools = ! this . state . schoolsByState ? null : this . state . schoolsByState
51+ . map ( school =>
52+ (
53+ < SchoolCard
54+ schoolName = { school . name }
55+ link = { school . url }
56+ schoolAddress = { school . locations [ 0 ] . address1 }
57+ schoolCity = { school . locations [ 0 ] . city }
58+ schoolState = { school . locations [ 0 ] . state }
59+ logo = { school . logo }
60+ GI = { school . va_accepted ? 'Yes' : 'No' }
61+ fullTime = { school . full_time ? 'Full-Time' : 'Flexible' }
62+ hardware = { school . hardware_included ? 'Yes' : 'No' }
63+ />
64+ )
65+ ) ;
3266 return (
3367 < Section
3468 id = "schoolsByState"
@@ -42,6 +76,9 @@ class StateSortedSchools extends Component {
4276 onChange = { this . onSearchChange }
4377 id = "search"
4478 />
79+ < div className = { styles . stateSchool } >
80+ { stateSchools }
81+ </ div >
4582 </ Section >
4683 ) ;
4784 }
0 commit comments