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 838B

1234567891011121314151617181920212223242526272829303132333435
  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. async getMediaById({ commit }, ids) {
  12. commit('CLEAR_MEDIA')
  13. commit('MEDIA_LOADED', false)
  14. const p = ids.map(async id => {
  15. return await api.getSingleMedia(id, media => {
  16. commit('STORE_FETCHED_MEDIA', { media })
  17. })
  18. })
  19. console.log(p)
  20. await Promise.all(p)
  21. commit('MEDIA_LOADED', true)
  22. }
  23. }
  24. const mutations = {
  25. STORE_FETCHED_MEDIA(state, { media }) { state.all.push() },
  26. CLEAR_MEDIA(state) { state.all = [] },
  27. MEDIA_LOADED(state, val) { state.loaded = val },
  28. }
  29. export default { state, getters, actions, mutations }