NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

publication.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import api from '../../utils/api'
  2. import { allBySlug, repackBySort } from './arrangements'
  3. const state = {
  4. all: [],
  5. loaded: false,
  6. singlePublication: null,
  7. }
  8. const getters = {
  9. allPublications: state => state.all,
  10. allPublicationsBySlug: state => allBySlug(state),
  11. allPublicationsLoaded: state => state.loaded,
  12. }
  13. const actions = {
  14. getAllPublications({ commit }, { sortType, params }) {
  15. commit('CLEAR_PUBLICATIONS')
  16. commit('PUBLICATIONS_LOADED', false)
  17. const storeFetch = publications => {
  18. let repacked = repackBySort(publications, sortType)
  19. commit('STORE_FETCHED_PUBLICATIONS', { publications: repacked })
  20. commit('PUBLICATIONS_LOADED', true)
  21. }
  22. return api.getByType({
  23. type: 'publication',
  24. sort: sortType,
  25. params,
  26. cb: storeFetch,
  27. })
  28. },
  29. getMorePublications({ commit }, { sortType, params }) {
  30. const storeFetch = publications => {
  31. let repacked = publications
  32. commit('ADD_TO_FETCHED_PUBLICATIONS', { publications: repacked })
  33. commit('PUBLICATIONS_LOADED', true)
  34. }
  35. return api.getByType({
  36. type: 'publication',
  37. sort: sortType,
  38. params,
  39. cb: storeFetch,
  40. })
  41. },
  42. getSinglePublication({ commit }, id) {
  43. commit('CLEAR_SINGLE_PUBLICATIONS')
  44. commit('PUBLICATIONS_LOADED', false)
  45. return api.getSingleType('publication', id, publication => {
  46. commit('STORE_FETCHED_SINGLE_PUBLICATION', publication)
  47. commit('PUBLICATIONS_LOADED', true)
  48. })
  49. },
  50. }
  51. const mutations = {
  52. ADD_TO_FETCHED_PUBLICATIONS(state, { publications }) {
  53. state.all = [...state.all, ...publications]
  54. },
  55. STORE_FETCHED_PUBLICATIONS(state, { publications }) {
  56. state.all = publications
  57. },
  58. STORE_FETCHED_SINGLE_PUBLICATION(state, publication) {
  59. state.singlePublication = publication
  60. },
  61. CLEAR_PUBLICATIONS(state) {
  62. state.all = []
  63. },
  64. CLEAR_SINGLE_PUBLICATIONS(state) {
  65. state.singlePublication = null
  66. },
  67. PUBLICATIONS_LOADED(state, val) {
  68. state.loaded = val
  69. },
  70. }
  71. export default { state, getters, actions, mutations }