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.

exhibition.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import api from '../../utils/api'
  2. const state = {
  3. all: [],
  4. loaded: false,
  5. singleExhibition: null,
  6. }
  7. const getters = {
  8. allExhibitions: state => state.all,
  9. allExhibitionsLoaded: state => state.loaded,
  10. pastExhibitions: state => {
  11. return state.all.filter(exhibition => {
  12. const now = new Date()
  13. return parseInt(exhibition.end) > now
  14. })
  15. },
  16. upcomingAndCurrentExhibitions: state => {
  17. return state.all
  18. // return state.all.filter(exhibition => {
  19. // const now = new Date()
  20. // // return parseInt(exhibition.end) <= now
  21. // return parseInt(exhibition.end) <= now
  22. // })
  23. },
  24. }
  25. const actions = {
  26. getAllExhibitions({ commit }, sortType) {
  27. commit('CLEAR_EXHIBITIONS')
  28. commit('EXHIBITIONS_LOADED', false)
  29. return api.getByType('exhibitions', sortType, exhibitions => {
  30. commit('STORE_FETCHED_EXHIBITIONS', { exhibitions })
  31. commit('EXHIBITIONS_LOADED', true)
  32. })
  33. },
  34. getSingleExhibition({ commit }, id) {
  35. commit('CLEAR_SINGLE_EXHIBITIONS')
  36. commit('EXHIBITIONS_LOADED', false)
  37. api.getSingleType('exhibitions', id, exhibition => {
  38. commit('STORE_FETCHED_SINGLE_EXHIBITION', exhibition)
  39. commit('EXHIBITIONS_LOADED', true)
  40. })
  41. },
  42. }
  43. const mutations = {
  44. STORE_FETCHED_EXHIBITIONS(state, { exhibitions }) {
  45. state.all = exhibitions
  46. },
  47. STORE_FETCHED_SINGLE_EXHIBITION(state, exhibition) {
  48. state.singleExhibition = exhibition
  49. },
  50. CLEAR_EXHIBITIONS(state) {
  51. state.all = []
  52. },
  53. CLEAR_SINGLE_EXHIBITIONS(state) {
  54. state.singleExhibition = null
  55. },
  56. EXHIBITIONS_LOADED(state, val) {
  57. state.loaded = val
  58. },
  59. }
  60. export default { state, getters, actions, mutations }