57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
|
import Vue from "vue";
|
||
|
import Vuex from "vuex";
|
||
|
import { jugglService } from "@/services/juggl.service.js";
|
||
|
|
||
|
Vue.use(Vuex);
|
||
|
|
||
|
export default new Vuex.Store({
|
||
|
state: {
|
||
|
apiUrl: "https://juggl.giller.dev/api",
|
||
|
apiKey: undefined,
|
||
|
user: undefined,
|
||
|
projects: [],
|
||
|
records: [],
|
||
|
},
|
||
|
mutations: {
|
||
|
setKey(state, key) {
|
||
|
state.key = key;
|
||
|
},
|
||
|
setProjects(state, projects) {
|
||
|
state.projects = projects;
|
||
|
},
|
||
|
setRecords(state, records) {
|
||
|
state.records = records;
|
||
|
},
|
||
|
},
|
||
|
getters: {
|
||
|
runningRecords: (state) => {
|
||
|
return state.records.filter((record) => record.running);
|
||
|
},
|
||
|
finishedRecords: (state) => {
|
||
|
return state.records.filter((record) => !record.running);
|
||
|
},
|
||
|
apiKey: (state) => state.apiKey,
|
||
|
user: (state) => state.user,
|
||
|
apiUrl: (state) => state.apiUrl,
|
||
|
isLoggedIn: (state) => !!state.apiKey,
|
||
|
records: (state) => state.records,
|
||
|
projects: (state) => state.projects,
|
||
|
getProjectById: (state, getters) => (id) => {
|
||
|
return getters.projects.find(
|
||
|
(project) => project.project_id === id
|
||
|
);
|
||
|
},
|
||
|
getRecordById: (state, getters) => (id) => {
|
||
|
return getters.records.find((record) => record.record_id === id);
|
||
|
},
|
||
|
},
|
||
|
actions: {
|
||
|
loadProjects({ commit }) {
|
||
|
commit("setProjects");
|
||
|
},
|
||
|
login({ commit, userId, apiKey }) {
|
||
|
return jugglService.login();
|
||
|
},
|
||
|
},
|
||
|
});
|