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.

episode.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import api from '../../utils/api'
  2. const state = {
  3. all: [],
  4. loaded: false,
  5. singleEpisode: null,
  6. }
  7. const getters = {
  8. allEpisodes: state => state.all,
  9. allEpisodesBySlug: state =>
  10. Object.values(state.all).reduce((bySlug, episode) => {
  11. bySlug[episode.slug] = episode
  12. return bySlug
  13. }, {}),
  14. allEpisodesLoaded: state => state.loaded,
  15. }
  16. const actions = {
  17. getAllEpisodes({ commit }, sortType) {
  18. commit('CLEAR_EPISODES')
  19. commit('EPISODES_LOADED', false)
  20. return api.getByType('episodes', sortType, episodes => {
  21. commit('STORE_FETCHED_EPISODES', { episodes })
  22. commit('EPISODES_LOADED', true)
  23. })
  24. },
  25. getSingleEpisode({ commit }, id) {
  26. commit('CLEAR_SINGLE_EPISODE')
  27. commit('EPISODES_LOADED', false)
  28. api.getSingleType('episodes', id, episode => {
  29. commit('STORE_FETCHED_SINGLE_EPISODE', episode)
  30. commit('EPISODES_LOADED', true)
  31. })
  32. },
  33. }
  34. const mutations = {
  35. STORE_FETCHED_EPISODES(state, { episodes }) {
  36. state.all = episodes
  37. },
  38. STORE_FETCHED_SINGLE_EPISODE(state, episode) {
  39. state.singleEpisode = episode
  40. },
  41. CLEAR_EPISODES(state) {
  42. state.all = []
  43. },
  44. CLEAR_SINGLE_EPISODE(state) {
  45. state.episode = null
  46. },
  47. EPISODES_LOADED(state, val) {
  48. state.loaded = val
  49. },
  50. }
  51. export default { state, getters, actions, mutations }