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

Commit daf6d84

Browse files
committed
Implement fuzzy search and fix flex display of results
1 parent fdb8d8c commit daf6d84

2 files changed

Lines changed: 23 additions & 17 deletions

File tree

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
.noteForSchoolReps {
2-
text-align: center;
3-
font-size: 1em;
4-
margin: 15px 0 0 0;
5-
}
6-
71
.partnerSchools {
82
display: flex;
93
flex-flow: row wrap;
@@ -13,4 +7,10 @@
137

148
.intro {
159
padding: 0 0 2.5% 0;
10+
}
11+
12+
.noteForSchoolReps {
13+
text-align: center;
14+
font-size: 1em;
15+
margin: 15px 0 0 0;
1616
}

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,31 @@ class StateSortedSchools extends Component {
2323
}
2424

2525
onSearchChange = (value) => {
26-
// const regex = new RegExp(value, 'gi');
27-
// const arr = this.state.by_state.match(regex);
28-
// this.setState({ stateList: arr });
29-
this.setState({ query: value });
30-
this.setState({ schoolsByState: this.searchState(value) });
26+
if (value.length > 1) {
27+
// Prevent query with just one character in search field
28+
this.setState({ query: value });
29+
this.setState({ schoolsByState: this.searchState(value) });
30+
}
3131
}
3232

3333
searchState = (string) => {
34-
const stringFormat = string.replace(/\w\S*/g, txt => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase());
34+
const stringFormat = string.replace(/\w\S*/g, txt =>
35+
txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
36+
);
3537
const schools = [];
38+
3639
this.state.schools.forEach((school) => {
37-
const locations = school.locations.filter(location =>
38-
location.state === stringFormat
39-
);
40+
// Search non-online locations for input per key stroke
41+
const locations = school.locations.filter(location => location.state !== undefined)
42+
.filter(location => location.state.includes(stringFormat));
43+
4044
if (locations.length > 0) {
4145
const newSchool = Object.assign({}, school);
4246
newSchool.locations = locations;
4347
schools.push(newSchool);
4448
}
4549
});
50+
4651
return schools;
4752
}
4853

@@ -62,7 +67,8 @@ class StateSortedSchools extends Component {
6267
hardware={school.hardware_included ? 'Yes' : 'No'}
6368
/>
6469
)
65-
);
70+
);
71+
6672
return (
6773
<Section
6874
id="schoolsByState"
@@ -76,7 +82,7 @@ class StateSortedSchools extends Component {
7682
onChange={this.onSearchChange}
7783
id="search"
7884
/>
79-
<div className={styles.stateSchool}>
85+
<div className={styles.stateSchools}>
8086
{stateSchools}
8187
</div>
8288
</Section>

0 commit comments

Comments
 (0)