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

Commit 17573ce

Browse files
committed
Reorganize fetches to stop breaking lifecycle
1 parent d0833b4 commit 17573ce

2 files changed

Lines changed: 14 additions & 20 deletions

File tree

src/scenes/home/codeSchools/approvedSchools/approvedSchools.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,25 @@ import Section from 'shared/components/section/section';
44
import SchoolCard from 'shared/components/schoolCard/schoolCard';
55
import styles from './approvedSchools.css';
66

7-
const gettingSchoolData = fetch('https://api.operationcode.org/api/v1/code_schools.json')
8-
.then(response => response.json());
9-
107
class ApprovedSchools extends Component {
118
constructor(props) {
129
super(props);
1310
this.state = {
1411
vaSchools: null
1512
};
16-
}
1713

18-
componentWillMount() {
19-
gettingSchoolData.then((data) => {
20-
this.setState({ vaSchools: this.getApprovedSchools(data) });
21-
});
14+
fetch('https://api.operationcode.org/api/v1/code_schools.json')
15+
.then(response => response.json()).then(data =>
16+
this.setState({ vaSchools: this.getApprovedSchools(data) })
17+
);
2218
}
2319

2420
getApprovedSchools = (schools) => {
25-
const approvedSchools = [];
21+
let approvedSchools = [];
2622
schools.forEach((school) => {
2723
const locations = school.locations.filter(location => location.va_accepted === true);
2824
if (locations.length > 0) {
29-
approvedSchools.push(locations.map(location =>
25+
approvedSchools = approvedSchools.concat(locations.map(location =>
3026
Object.assign({}, _.omit(school, ['locations']), location)));
3127
}
3228
});
@@ -35,20 +31,20 @@ class ApprovedSchools extends Component {
3531
}
3632

3733
render() {
34+
console.log(JSON.stringify(this.state.vaSchools, null, 2));
3835
const vaSchools = !this.state.vaSchools ? null : this.state.vaSchools
39-
.filter(school => school.locations[0].va_accepted)
4036
.map(school =>
4137
(
4238
<SchoolCard
43-
key={school.name}
39+
key={school.address}
4440
alt={school.name}
4541
schoolName={school.name}
4642
link={school.url}
47-
schoolAddress={school.locations[0].address1}
48-
schoolCity={school.locations[0].city}
49-
schoolState={school.locations[0].state}
43+
schoolAddress={school.address1}
44+
schoolCity={school.city}
45+
schoolState={school.state}
5046
logo={school.logo}
51-
GI={school.locations[0].va_accepted ? 'Yes' : 'No'}
47+
GI={school.va_accepted ? 'Yes' : 'No'}
5248
fullTime={school.full_time ? 'Full-Time' : 'Flexible'}
5349
hardware={school.hardware_included ? 'Yes' : 'No'}
5450
/>

src/scenes/home/codeSchools/onlineSchools/onlineSchools.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ import treehouseLogo from 'images/moocLogos/treehouse.jpg';
77
import udacityLogo from 'images/moocLogos/udacity.jpg';
88
import styles from './onlineSchools.css';
99

10-
const gettingSchoolData = fetch('https://api.operationcode.org/api/v1/code_schools.json')
11-
.then(response => response.json());
12-
1310
class OnlineSchools extends Component {
1411
constructor(props) {
1512
super(props);
1613
this.state = {
1714
eSchools: null
1815
};
1916

20-
gettingSchoolData.then(data =>
17+
fetch('https://api.operationcode.org/api/v1/code_schools.json')
18+
.then(response => response.json()).then(data =>
2119
this.setState({ eSchools: data })
2220
);
2321
}

0 commit comments

Comments
 (0)