2019-11-13 21:40:14 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import Vuex from 'vuex';
|
2019-12-05 03:32:33 +00:00
|
|
|
import axios from 'axios';
|
|
|
|
//import * as _ from 'lodash/fp';
|
|
|
|
import router from '../router';
|
2019-11-13 21:40:14 +00:00
|
|
|
|
2019-12-05 21:26:45 +00:00
|
|
|
import getAuth from './auth';
|
|
|
|
|
2019-11-13 21:40:14 +00:00
|
|
|
Vue.use(Vuex);
|
|
|
|
|
2019-12-05 21:26:45 +00:00
|
|
|
|
2019-12-05 03:32:33 +00:00
|
|
|
const store = new Vuex.Store({
|
2019-11-14 02:59:17 +00:00
|
|
|
state: {
|
2019-12-05 03:32:33 +00:00
|
|
|
events: Array,
|
2019-11-15 19:00:40 +00:00
|
|
|
layout: 'cards',
|
2019-12-05 19:10:43 +00:00
|
|
|
loadedItems: Array,
|
2019-12-12 16:53:37 +00:00
|
|
|
loadedBoxes: Array,
|
2019-11-14 03:14:47 +00:00
|
|
|
},
|
2019-12-05 03:32:33 +00:00
|
|
|
getters: {
|
|
|
|
getEventSlug: state => state.route.params.event,
|
2019-12-12 16:53:37 +00:00
|
|
|
getActiveView: state => state.route.name,
|
2019-12-05 03:32:33 +00:00
|
|
|
},
|
2019-11-14 03:14:47 +00:00
|
|
|
mutations: {
|
2019-12-05 03:32:33 +00:00
|
|
|
replaceEvents(state, events) {
|
|
|
|
state.events = events;
|
|
|
|
},
|
2019-11-14 03:14:47 +00:00
|
|
|
changeEvent(state, event) {
|
2019-12-12 16:53:37 +00:00
|
|
|
router.push({path: `/${event.slug}/${state.currentview}`});
|
2019-12-05 22:27:24 +00:00
|
|
|
},
|
|
|
|
changeView(state, link) {
|
2019-12-12 16:53:37 +00:00
|
|
|
router.push({path: `/${state.route.params.event}/${link.path}`});
|
|
|
|
state.currentview = link.path;
|
2019-12-05 03:32:33 +00:00
|
|
|
},
|
|
|
|
replaceLoadedItems(state, newItems) {
|
|
|
|
state.loadedItems = newItems;
|
2019-11-15 19:00:40 +00:00
|
|
|
},
|
|
|
|
setLayout(state, layout) {
|
|
|
|
state.layout = layout;
|
2019-11-14 03:14:47 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
actions: {
|
2019-12-05 03:32:33 +00:00
|
|
|
async loadEvents({ commit }) {
|
|
|
|
const resp = await axios.get('https://c3lf.de/api/1/events', {
|
2019-12-05 21:26:45 +00:00
|
|
|
auth: getAuth(),
|
2019-12-05 03:32:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
commit('replaceEvents', resp.data);
|
|
|
|
},
|
|
|
|
changeEvent({ commit, dispatch }, eventName) {
|
|
|
|
commit('changeEvent', eventName);
|
|
|
|
dispatch('loadEventItems', eventName);
|
|
|
|
},
|
2019-12-05 22:27:24 +00:00
|
|
|
changeView({ commit }, link) {
|
|
|
|
commit('changeView', link);
|
|
|
|
},
|
2019-12-05 03:32:33 +00:00
|
|
|
async loadEventItems({ commit, state }) {
|
|
|
|
const resp = await axios.get(`https://c3lf.de/api/1/${state.route.params.event}/items`, {
|
2019-12-05 21:26:45 +00:00
|
|
|
auth: getAuth(),
|
2019-12-05 03:32:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
commit('replaceLoadedItems', resp.data);
|
2019-11-14 03:14:47 +00:00
|
|
|
}
|
2019-11-14 02:59:17 +00:00
|
|
|
}
|
2019-11-13 21:40:14 +00:00
|
|
|
});
|
2019-12-05 03:32:33 +00:00
|
|
|
|
|
|
|
export default store;
|
|
|
|
|
2019-12-05 22:27:24 +00:00
|
|
|
store.dispatch('loadEvents');
|
|
|
|
store.dispatch('loadEventItems');
|