refactor index.js
This commit is contained in:
parent
0f07f8b517
commit
b6ab1a8bb5
1 changed files with 16 additions and 17 deletions
|
@ -11,25 +11,24 @@ Vue.use(Vuex);
|
||||||
|
|
||||||
const store = new Vuex.Store({
|
const store = new Vuex.Store({
|
||||||
state: {
|
state: {
|
||||||
events: Array,
|
events: [],
|
||||||
layout: 'cards',
|
layout: 'cards',
|
||||||
loadedItems: Array,
|
loadedItems: [],
|
||||||
loadedBoxes: Array,
|
loadedBoxes: [],
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
getEventSlug: state => state.route.params.event,
|
getEventSlug: state => {
|
||||||
getActiveView: state => state.route.name,
|
console.log('foo', state.events);
|
||||||
|
return state.route && state.route.params.event? state.route.params.event : state.events.length ? state.events[0].slug : '36C3';
|
||||||
|
},
|
||||||
|
getActiveView: state => state.route.name || 'items',
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
replaceEvents(state, events) {
|
replaceEvents(state, events) {
|
||||||
state.events = events;
|
state.events = events;
|
||||||
},
|
},
|
||||||
changeEvent(state, event) {
|
changeView(state, {view, slug}) {
|
||||||
router.push({path: `/${event.slug}/${state.currentview}`});
|
router.push({path: `/${slug}/${view}`});
|
||||||
},
|
|
||||||
changeView(state, link) {
|
|
||||||
router.push({path: `/${state.route.params.event}/${link.path}`});
|
|
||||||
state.currentview = link.path;
|
|
||||||
},
|
},
|
||||||
replaceLoadedItems(state, newItems) {
|
replaceLoadedItems(state, newItems) {
|
||||||
state.loadedItems = newItems;
|
state.loadedItems = newItems;
|
||||||
|
@ -46,15 +45,15 @@ const store = new Vuex.Store({
|
||||||
|
|
||||||
commit('replaceEvents', resp.data);
|
commit('replaceEvents', resp.data);
|
||||||
},
|
},
|
||||||
changeEvent({ commit, dispatch }, eventName) {
|
changeEvent({ dispatch, getters}, eventName) {
|
||||||
commit('changeEvent', eventName);
|
router.push({path: `/${eventName.slug}/${getters.getActiveView}`});
|
||||||
dispatch('loadEventItems', eventName);
|
dispatch('loadEventItems', eventName);
|
||||||
},
|
},
|
||||||
changeView({ commit }, link) {
|
changeView({ getters }, link) {
|
||||||
commit('changeView', link);
|
router.push({path: `/${getters.getEventSlug}/${link.path}`});
|
||||||
},
|
},
|
||||||
async loadEventItems({ commit, state }) {
|
async loadEventItems({ commit, getters }) {
|
||||||
const resp = await axios.get(`https://c3lf.de/api/1/${state.route.params.event}/items`, {
|
const resp = await axios.get(`https://c3lf.de/api/1/${getters.getEventSlug}/items`, {
|
||||||
auth: getAuth(),
|
auth: getAuth(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue