2020-03-17 22:16:34 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import Vuex, { Store } from "vuex";
|
|
|
|
import Services from '../services';
|
2020-05-01 05:55:26 +00:00
|
|
|
|
2020-03-17 22:16:34 +00:00
|
|
|
Vue.use(Vuex);
|
|
|
|
const store = new Store({
|
|
|
|
strict: true,
|
|
|
|
state: {
|
2020-04-29 23:45:50 +00:00
|
|
|
inCall: false,
|
2020-04-30 02:34:14 +00:00
|
|
|
user: { name: 'loading...', is_admin: false, id: null, books: [] },
|
2020-04-12 14:25:42 +00:00
|
|
|
notifications: []
|
2020-03-17 22:16:34 +00:00
|
|
|
},
|
|
|
|
getters: {
|
|
|
|
user(state) {
|
|
|
|
return state.user;
|
2020-04-12 14:25:42 +00:00
|
|
|
},
|
|
|
|
notifications(state) {
|
|
|
|
return state.notifications;
|
2020-04-29 23:45:50 +00:00
|
|
|
},
|
|
|
|
inCall(state) {
|
|
|
|
return state.inCall;
|
2020-03-17 22:16:34 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mutations: {
|
2020-04-12 14:25:42 +00:00
|
|
|
setUser(state, user) {
|
2020-03-17 22:16:34 +00:00
|
|
|
state.user = user;
|
2020-04-12 14:25:42 +00:00
|
|
|
},
|
|
|
|
notify(state, notification) {
|
|
|
|
const id = Math.ceil(Math.random() * 1000);
|
|
|
|
state.notifications.push({ ...notification, id });
|
|
|
|
const dispatch = this.dispatch;
|
|
|
|
setTimeout(() => {
|
|
|
|
dispatch("dismissNotification", id);
|
|
|
|
}, 5000);
|
|
|
|
},
|
|
|
|
dismissNotification(state, noteId: number) {
|
|
|
|
state.notifications = state.notifications.filter(n => n.id != noteId);
|
2020-04-29 23:45:50 +00:00
|
|
|
},
|
|
|
|
callEnded(state) {
|
|
|
|
state.inCall = false;
|
|
|
|
},
|
2020-05-01 05:55:26 +00:00
|
|
|
callStarted(state) {
|
2020-04-29 23:45:50 +00:00
|
|
|
state.inCall = true;
|
2020-03-17 22:16:34 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
actions: {
|
2020-04-29 23:45:50 +00:00
|
|
|
async getUser(ctx, userId?: number) {
|
2020-03-17 22:16:34 +00:00
|
|
|
const user = await Services.ApiService.getUser(userId);
|
|
|
|
ctx.commit('setUser', user);
|
2020-05-01 05:55:26 +00:00
|
|
|
return user;
|
2020-03-17 22:16:34 +00:00
|
|
|
},
|
2020-04-12 14:25:42 +00:00
|
|
|
notify(ctx, notification: { message: string, level?: "info" | "warning" | "success" | "danger" }) {
|
|
|
|
ctx.commit("notify", notification);
|
|
|
|
},
|
|
|
|
dismissNotification(ctx, id: number) {
|
|
|
|
ctx.commit("dismissNotification", id);
|
2020-04-29 23:45:50 +00:00
|
|
|
},
|
|
|
|
callEnded(ctx) {
|
|
|
|
ctx.commit('callEnded');
|
|
|
|
},
|
2020-05-01 05:55:26 +00:00
|
|
|
callStarted(ctx) {
|
|
|
|
ctx.commit('callStarted');
|
2020-04-12 14:25:42 +00:00
|
|
|
}
|
2020-03-17 22:16:34 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
export default store;
|