78 lines
1.8 KiB
JavaScript
78 lines
1.8 KiB
JavaScript
|
// src/store/index.js
|
||
|
|
||
|
import Vue from 'vue';
|
||
|
import Vuex from 'vuex';
|
||
|
import { fetchchaine, fetchemission, authenticate } from '../api';
|
||
|
import { isValidJwt, EventBus } from '../utils';
|
||
|
|
||
|
Vue.use(Vuex);
|
||
|
const actions = {
|
||
|
// asynchronous operations
|
||
|
getchaine(context, { num }) {
|
||
|
return fetchchaine(num)
|
||
|
.then((res) => {
|
||
|
if (res.status === 200) {
|
||
|
context.dispatch('getemission', { chaine: num, name: res.data });
|
||
|
} else {
|
||
|
context.commit('push_chaine', { chaine: num, name: res.data });
|
||
|
}
|
||
|
})
|
||
|
.catch((error) => {
|
||
|
// eslint-disable-next-line
|
||
|
console.error(error);
|
||
|
});
|
||
|
},
|
||
|
getemission(context, { chaine, name }) {
|
||
|
return fetchemission(chaine)
|
||
|
.then((resEmission) => {
|
||
|
context.commit('push_chaine', { chaine, name, emission: resEmission.data });
|
||
|
})
|
||
|
.catch((error) => {
|
||
|
context.commit('push_chaine', { chaine, name });
|
||
|
console.error(error);
|
||
|
});
|
||
|
},
|
||
|
setStorename(context, userData) {
|
||
|
context.commit('setUserData', { userData });
|
||
|
},
|
||
|
// register (context, userData) {
|
||
|
// context.commit('setUserData', { userData })
|
||
|
// return register(userData)
|
||
|
// .then(context.dispatch('login', userData))
|
||
|
// .catch(error => {
|
||
|
// console.log('Error Registering: ', error)
|
||
|
// EventBus.$emit('failedRegistering: ', error)
|
||
|
// })
|
||
|
// }
|
||
|
};
|
||
|
|
||
|
const mutations = {
|
||
|
// isolated data mutations
|
||
|
|
||
|
setUserData(state, payload) {
|
||
|
console.log('setUserData payload = ', payload);
|
||
|
state.user = payload.userData.name;
|
||
|
},
|
||
|
|
||
|
};
|
||
|
|
||
|
const getters = {
|
||
|
// reusable data accessors
|
||
|
name(state) {
|
||
|
return (state.user);
|
||
|
},
|
||
|
};
|
||
|
|
||
|
const state = {
|
||
|
// single source of data
|
||
|
user: '',
|
||
|
};
|
||
|
const store = new Vuex.Store({
|
||
|
state,
|
||
|
actions,
|
||
|
mutations,
|
||
|
getters,
|
||
|
});
|
||
|
|
||
|
export default store;
|