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.

media.js 747B

1234567891011121314151617181920212223242526272829303132
  1. import api from '../../utils/api'
  2. const state = {
  3. all: {},
  4. loaded: false,
  5. }
  6. const getters = {
  7. allMedia: state => state.all,
  8. allMediaLoaded: state => state.loaded,
  9. }
  10. const actions = {
  11. getMediaById({ commit }, ids) {
  12. commit('CLEAR_MEDIA')
  13. commit('MEDIA_LOADED', false)
  14. ids.forEach(id => {
  15. api.getSingleMedia(id, media => {
  16. commit('STORE_FETCHED_MEDIA', { media })
  17. })
  18. })
  19. commit('MEDIA_LOADED', true)
  20. }
  21. }
  22. const mutations = {
  23. STORE_FETCHED_MEDIA(state, { media }) { state.all = media },
  24. CLEAR_MEDIA(state) { state.all = [] },
  25. MEDIA_LOADED(state, val) { state.loaded = val },
  26. }
  27. export default { state, getters, actions, mutations }