Skip to content
This repository was archived by the owner on Jun 10, 2019. It is now read-only.

Commit 10acac3

Browse files
committed
Adjust the search function to return schools again
1 parent 592d58f commit 10acac3

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

src/scenes/home/codeSchools/stateSortedSchools/stateSortedSchools.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Section from 'shared/components/section/section';
33
import SchoolCard from 'shared/components/schoolCard/schoolCard';
44
import FormInput from 'shared/components/form/formInput/formInput';
55
import styles from './stateSortedSchools.css';
6-
import stateCodes from '../stateCodes.json';
6+
77

88
const 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

Comments
 (0)