NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

page.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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, params }) {
  16. commit('PAGES_LOADED', false)
  17. return await api.getByType({
  18. type: 'page',
  19. sort: sortType,
  20. params,
  21. cb: pages => {
  22. commit('STORE_FETCHED_PAGES', { pages })
  23. commit('PAGES_LOADED', true)
  24. },
  25. })
  26. },
  27. getSinglePage({ commit }, id) {
  28. commit('CLEAR_SINGLE_PAGE')
  29. commit('PAGES_LOADED', false)
  30. return api.getSingleType('page', id, page => {
  31. commit('STORE_FETCHED_SINGLE_PAGE', page)
  32. commit('PAGES_LOADED', true)
  33. })
  34. },
  35. }
  36. // mutations
  37. const mutations = {
  38. STORE_FETCHED_PAGES(state, { pages }) {
  39. state.all = pages
  40. },
  41. STORE_FETCHED_SINGLE_PAGE(state, page) {
  42. state.singlePage = page
  43. },
  44. CLEAR_PAGES(state) {
  45. state.all = []
  46. },
  47. CLEAR_SINGLE_PAGE(state) {
  48. state.singlePage = null
  49. },
  50. PAGES_LOADED(state, val) {
  51. state.loaded = val
  52. },
  53. }
  54. export default { state, getters, actions, mutations }