NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import api from '../../utils/api'
  2. // initial state
  3. const state = {
  4. all: [],
  5. loaded: false,
  6. singlePage: null,
  7. }
  8. // getters
  9. const getters = {
  10. allPages: state => state.all,
  11. allPagesLoaded: state => state.loaded,
  12. }
  13. // actions
  14. const actions = {
  15. async getAllPages({ commit }, sortType) {
  16. commit('PAGES_LOADED', false)
  17. return await api.getByType({ type: 'page', sort: sortType, cb: pages => {
  18. commit('STORE_FETCHED_PAGES', { pages })
  19. commit('PAGES_LOADED', true)
  20. }
  21. })
  22. },
  23. getSinglePage({ commit }, id) {
  24. commit('CLEAR_SINGLE_PAGE')
  25. commit('PAGES_LOADED', false)
  26. api.getSingleType('page', id, page => {
  27. commit('STORE_FETCHED_SINGLE_PAGE', page)
  28. commit('PAGES_LOADED', true)
  29. })
  30. },
  31. }
  32. // mutations
  33. const mutations = {
  34. STORE_FETCHED_PAGES(state, { pages }) {
  35. state.all = pages
  36. },
  37. STORE_FETCHED_SINGLE_PAGE(state, page) {
  38. state.singlePage = page
  39. },
  40. CLEAR_PAGES(state) {
  41. state.all = []
  42. },
  43. CLEAR_SINGLE_PAGE(state) {
  44. state.singlePage = null
  45. },
  46. PAGES_LOADED(state, val) {
  47. state.loaded = val
  48. },
  49. }
  50. export default { state, getters, actions, mutations }