| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import api from '../../utils/api'
-
- const state = {
- all: [],
- loaded: false,
- singleExhibition: null,
- }
-
- const getters = {
- allExhibitions: state => state.all,
- allExhibitionsLoaded: state => state.loaded,
- pastExhibitions: state => {
- return state.all.filter(exhibition => {
- const now = new Date()
- return parseInt(exhibition.end) > now
- })
- },
- upcomingAndCurrentExhibitions: state => {
- return state.all
- // return state.all.filter(exhibition => {
- // const now = new Date()
- // // return parseInt(exhibition.end) <= now
- // return parseInt(exhibition.end) <= now
- // })
- },
- }
-
- const actions = {
- getAllExhibitions({ commit }, sortType) {
- commit('CLEAR_EXHIBITIONS')
- commit('EXHIBITIONS_LOADED', false)
- return api.getByType('exhibitions', sortType, exhibitions => {
- commit('STORE_FETCHED_EXHIBITIONS', { exhibitions })
- commit('EXHIBITIONS_LOADED', true)
- })
- },
- getSingleExhibition({ commit }, id) {
- commit('CLEAR_SINGLE_EXHIBITIONS')
- commit('EXHIBITIONS_LOADED', false)
- api.getSingleType('exhibitions', id, exhibition => {
- commit('STORE_FETCHED_SINGLE_EXHIBITION', exhibition)
- commit('EXHIBITIONS_LOADED', true)
- })
- },
- }
-
- const mutations = {
- STORE_FETCHED_EXHIBITIONS(state, { exhibitions }) {
- state.all = exhibitions
- },
- STORE_FETCHED_SINGLE_EXHIBITION(state, exhibition) {
- state.singleExhibition = exhibition
- },
- CLEAR_EXHIBITIONS(state) {
- state.all = []
- },
- CLEAR_SINGLE_EXHIBITIONS(state) {
- state.singleExhibition = null
- },
- EXHIBITIONS_LOADED(state, val) {
- state.loaded = val
- },
- }
-
- export default { state, getters, actions, mutations }
|