Created
May 27, 2020 12:55
-
-
Save scottpdawson/fa2a46faf465f5b6da30135d353719ad to your computer and use it in GitHub Desktop.
Fetching ski resort data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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