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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import api from '../../utils/api'
  2. import { allBySlug, repackBySort } from './arrangements'
  3. const state = {
  4. all: [],
  5. loaded: false,
  6. singleGuide: null,
  7. }
  8. const getters = {
  9. allGuides: state => state.all,
  10. allGuidesBySlug: state => allBySlug(state),
  11. allGuidesLoaded: state => state.loaded,
  12. }
  13. const actions = {
  14. getAllGuides({ commit }, { sortType, params }) {
  15. commit('CLEAR_GUIDES')
  16. commit('GUIDES_LOADED', false)
  17. const storeFetch = guides => {
  18. let repacked = repackBySort(guides, sortType)
  19. commit('STORE_FETCHED_GUIDES', { guides: repacked })
  20. commit('GUIDES_LOADED', true)
  21. }
  22. return api.getByType({
  23. type: 'guide',
  24. sort: sortType,
  25. params,
  26. cb: storeFetch,
  27. })
  28. },
  29. getMoreGuides({ commit }, { sortType, params }) {
  30. const storeFetch = guides => {
  31. let repacked = guides
  32. commit('ADD_TO_FETCHED_GUIDES', { guides: repacked })
  33. commit('GUIDES_LOADED', true)
  34. }
  35. return api.getByType({
  36. type: 'guide',
  37. sort: sortType,
  38. params,
  39. cb: storeFetch,
  40. })
  41. },
  42. getSingleGuide({ commit }, id) {
  43. commit('CLEAR_SINGLE_GUIDES')
  44. commit('GUIDES_LOADED', false)
  45. return api.getSingleType('guide', id, guide => {
  46. commit('STORE_FETCHED_SINGLE_GUIDE', guide)
  47. commit('GUIDES_LOADED', true)
  48. })
  49. },
  50. }
  51. const mutations = {
  52. ADD_TO_FETCHED_GUIDES(state, { guides }) {
  53. state.all = [...state.all, ...guides]
  54. },
  55. STORE_FETCHED_GUIDES(state, { guides }) {
  56. state.all = guides
  57. },
  58. STORE_FETCHED_SINGLE_GUIDE(state, guide) {
  59. state.singleGuide = guide
  60. },
  61. CLEAR_GUIDES(state) {
  62. state.all = []
  63. },
  64. CLEAR_SINGLE_GUIDES(state) {
  65. state.singleGuide = null
  66. },
  67. GUIDES_LOADED(state, val) {
  68. state.loaded = val
  69. },
  70. }
  71. export default { state, getters, actions, mutations }