NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import api from '../../utils/api'
  2. const state = {
  3. all: [],
  4. loaded: false,
  5. singleArtist: null,
  6. }
  7. const getters = {
  8. allArtists: state => state.all,
  9. allArtistsBySlug: state => Object.values(state.all).reduce((bySlug, artist) => {
  10. bySlug[artist.slug] = artist
  11. return bySlug
  12. }, {}),
  13. allArtistsLoaded: state => state.loaded
  14. }
  15. const actions = {
  16. getAllArtists({ commit }, sortType) {
  17. commit('CLEAR_ARTISTS')
  18. commit('ARTISTS_LOADED', false)
  19. return api.getByType('artists', sortType, artists => {
  20. commit('STORE_FETCHED_ARTISTS', { artists })
  21. commit('ARTISTS_LOADED', true)
  22. })
  23. },
  24. getSingleArtist({ commit }, id) {
  25. console.log('getting single Artist...')
  26. commit('CLEAR_SINGLE_ARTIST')
  27. commit('ARTISTS_LOADED', false)
  28. api.getSingleType('artists', id, artist => {
  29. commit('STORE_FETCHED_SINGLE_ARTIST', artist)
  30. commit('ARTISTS_LOADED', true)
  31. })
  32. }
  33. }
  34. const mutations = {
  35. STORE_FETCHED_ARTISTS(state, { artists }) { state.all = artists },
  36. STORE_FETCHED_SINGLE_ARTIST(state, artist) { state.singleArtist = artist },
  37. CLEAR_ARTISTS(state) { state.all = [] },
  38. CLEAR_SINGLE_ARTIST(state) { state.singleArtist = null },
  39. ARTISTS_LOADED(state, val) { state.loaded = val },
  40. }
  41. export default { state, getters, actions, mutations }