From 509fadca110d9c20120787e6450a84c22b1a73b7 Mon Sep 17 00:00:00 2001 From: jedi Date: Fri, 20 Dec 2019 00:19:38 +0100 Subject: [PATCH] squash stuff --- .env.example | 2 -- .gitignore | 3 ++- src/main.js | 2 +- src/store/index.js | 49 +++++++++++++++++++++------------------------- 4 files changed, 25 insertions(+), 31 deletions(-) delete mode 100644 .env.example diff --git a/.env.example b/.env.example deleted file mode 100644 index 46907ab..0000000 --- a/.env.example +++ /dev/null @@ -1,2 +0,0 @@ -VUE_APP_CONFIG_API_USER=rest api user -VUE_APP_CONFIG_API_PASSWORD=rest api password \ No newline at end of file diff --git a/.gitignore b/.gitignore index db5b83e..f0269d9 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ yarn.lock *.sln *.sw? -src/store/auth.js \ No newline at end of file +src/store/auth.js +src/config.js \ No newline at end of file diff --git a/src/main.js b/src/main.js index ba45494..c12ec30 100644 --- a/src/main.js +++ b/src/main.js @@ -1,8 +1,8 @@ import Vue from 'vue'; import App from './App.vue'; +import { sync } from 'vuex-router-sync'; import store from './store'; import router from './router'; -import { sync } from 'vuex-router-sync'; // bootstrap import 'jquery/dist/jquery.min.js'; diff --git a/src/store/index.js b/src/store/index.js index b7039b7..315480f 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,13 +1,15 @@ import Vue from 'vue'; import Vuex from 'vuex'; -import axios from 'axios'; +import AxiosBootstrap from 'axios'; +import config from '../config'; //import * as _ from 'lodash/fp'; import router from '../router'; -import getAuth from './auth'; - Vue.use(Vuex); - +const axios = AxiosBootstrap.create({ + baseURL: config.service.url, + auth: config.service.auth +}); const store = new Vuex.Store({ state: { @@ -15,7 +17,6 @@ const store = new Vuex.Store({ layout: 'cards', loadedItems: [], loadedBoxes: [], - apiUrl: 'https://c3lf.de/api', }, getters: { getEventSlug: state => state.route && state.route.params.event? state.route.params.event : state.events.length ? state.events[0].slug : '36C3', @@ -38,14 +39,15 @@ const store = new Vuex.Store({ replaceBoxes(state, loadedBoxes) { state.loadedBoxes = loadedBoxes; }, + updateItem(state, updatedItem) { + const item = state.loadedItems.filter(({ item_uid }) => item_uid === updatedItem.item_uid)[0]; + Object.assign(item, updatedItem); + } }, actions: { - async loadEvents({ commit, state }) { - const resp = await axios.get(`${state.apiUrl}/1/events`, { - auth: getAuth(), - }); - - commit('replaceEvents', resp.data); + async loadEvents({ commit }) { + const { data } = await axios.get('/1/events'); + commit('replaceEvents', data); }, changeEvent({ dispatch, getters}, eventName) { router.push({path: `/${eventName.slug}/${getters.getActiveView}`}); @@ -54,24 +56,17 @@ const store = new Vuex.Store({ changeView({ getters }, link) { router.push({path: `/${getters.getEventSlug}/${link.path}`}); }, - async loadEventItems({ commit, state, getters }) { - const resp = await axios.get(`${state.apiUrl}/1/${getters.getEventSlug}/items`, { - auth: getAuth(), - }); - - commit('replaceLoadedItems', resp.data); + async loadEventItems({ commit, getters }) { + const { data } = await axios.get(`/1/${getters.getEventSlug}/items`); + commit('replaceLoadedItems', data); }, - async loadBoxes({ commit, state }) { - const resp = await axios.get(`${state.apiUrl}/1/boxes`, { - auth: getAuth(), - }); - - commit('replaceBoxes', resp.data); + async loadBoxes({ commit }) { + const { data } = await axios.get('/1/boxes'); + commit('replaceBoxes', data); }, - async updateItem({ getters, state }, item) { - axios.put(`${state.apiUrl}/1/${getters.getEventSlug}/item/${item.iid}`, item, { - auth: getAuth(), - }); + async updateItem({ commit, getters }, item) { + const { data } = await axios.put(`/1/${getters.getEventSlug}/item/${item.iid}`, item); + commit('updateItem', data); } } });