Skip to content

Instantly share code, notes, and snippets.

@scottpdawson

scottpdawson/App.js

Created May 27, 2020
Embed
What would you like to do?
Fetching ski resort data
async componentDidMount() {
// trigger data load from openskimap
axios
.get(`//tiles.skimap.org/geojson/ski_areas.geojson`)
.then((res) => {
const resorts =
res.data.features.map((resort) => ({
id: resort.properties.id,
point: getPointForResort(resort),
name: resort.properties.name,
...
isEpic: false,
isIkon: false,
})) || [];
// trigger data load from Firebase to get Epic/Ikon data
const ikonEpicFlags = firebase.database().ref();
ikonEpicFlags.on("value", (snapshot) => {
let epicIkon = snapshot.val();
let currentResorts = resorts;
epicIkon.forEach(function (epicIkonResort) {
// find resort ID within currentResorts
let matchedResort = currentResorts.find(
(o) => o.name === epicIkonResort.name
);
// set isIkon and isEpic within currentResorts
if (matchedResort) {
matchedResort.isEpic = epicIkonResort.epic === 1 ? true : false;
matchedResort.isIkon = epicIkonResort.ikon === 1 ? true : false;
}
});
this.setState({
resorts: currentResorts,
});
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.