diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-03-19 16:22:41 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-03-19 16:22:41 +0100 |
commit | 0d6bd4aefc4e651be3f2fff15043d598e852df54 (patch) | |
tree | 23703efd4a602ef8fe3c9236e84642d6843a4ba9 /src/store.js | |
parent | d383bd08f0266406d4b0c9eb68c76e62c9d4a460 (diff) |
feat: add loading
Diffstat (limited to 'src/store.js')
-rw-r--r-- | src/store.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/store.js b/src/store.js index 888add2..dab3529 100644 --- a/src/store.js +++ b/src/store.js @@ -6,10 +6,14 @@ Vue.use(Vuex) export default new Vuex.Store({ state: { api: process.env.VUE_APP_BACKEND_URL, + loading: false, commits: [], emails: {}, }, - get: { + getters: { + loading: state => { + return state.loading + }, commits: state => { return state.commits }, @@ -18,24 +22,29 @@ export default new Vuex.Store({ }, }, mutations: { + loading_state: (state, value) => { + state.loading = value + }, load_commits: (state, value) => { state.commits = value }, load_emails: (state, value) => { - console.log(JSON.stringify(value)) state.emails = value }, }, actions: { // Get all commits from the api backend async get_commits({commit}) { + commit('loading_state', true) await fetch(`${this.state.api}/commit/`) .then(async response => { commit('load_commits', await response.json()); }) + commit('loading_state', false) }, // Get all emails and map them like an hash async get_emails({commit}) { + commit('loading_state', true) await fetch(`${this.state.api}/email/`) .then(async response => { const emails_list = await response.json(); @@ -47,6 +56,7 @@ export default new Vuex.Store({ commit('load_emails', emails_obj); }) + commit('loading_state', false) }, }, modules: { |