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

Commit 1a939ab

Browse files
committed
Near-complete fix of fuzzy search - bug in log
When a user searches for "Car" a single code school shows up from North Carolina. In actuality, two schools should appear; one from NC, and one from SC.
1 parent a6fcd3d commit 1a939ab

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ 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';
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

1111
class 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

Comments
 (0)