Created
July 27, 2018 22:03
-
-
Save mtermoul/3a7f02fa0348a941f60af46c260dd8de to your computer and use it in GitHub Desktop.
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
... | |
actions: { | |
... | |
fetchCities ({commit, dispatch, state}) { | |
// will populate the cities from cosmic js REST API | |
const params = { | |
type_slug: 'cities' | |
} | |
Cosmic.getObjectsByType(params) | |
.then(data => { | |
let locations = {} | |
let country = '' | |
data.objects.forEach(city => { | |
const cityKey = city.slug.toUpperCase() | |
const stateKey = city.metadata.state.slug.toUpperCase() | |
... | |
locations[stateKey][cityKey].city = city.title | |
locations[stateKey][cityKey].state = city.metadata.state.title | |
locations[stateKey][cityKey].postalCode = city.metadata.postal_code | |
locations[stateKey][cityKey].dataUrl = city.metadata.data_url | |
locations[stateKey][cityKey].country = country | |
locations[stateKey][cityKey].geoPoint = { | |
latitude: city.metadata.lat, | |
longitude: city.metadata.lng | |
} | |
}) | |
commit('SET_AVAILABLE_LOCATIONS', locations) | |
// set the initial default location | |
dispatch('updateSelectedLocation', {state: 'FL', city: 'ORLANDO', postalCode: '32821'}) | |
}) | |
.catch(err => { | |
console.log(err) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment