summaryrefslogtreecommitdiff
path: root/src/store.js
blob: 2fd04eb306f8a5c43c9c55134fd570788b881abc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    api: process.env.VUE_APP_BACKEND_URL,
    loading: false,
    commits: [],
    emails: {},
  },
  getters: {
    loading: state => {
      return state.loading
    },
    commits: state => {
      return state.commits
    },
    emails: state => {
      return state.emails
    },
  },
  mutations: {
    loading_state: (state, value) => {
      state.loading = value
    },
    load_commits: (state, value) => {
      state.commits = value
    },
    load_emails: (state, 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}) {
      await fetch(`${this.state.api}/email/`)
        .then(async response => {
          const emails_list = await response.json();
          const emails_obj = emails_list
                                .reduce((dict, elem) => {
                                  dict[elem['email']] = elem['hash_md5']
                                  return dict;
                                }, {})

          commit('load_emails', emails_obj);
        })
    },
  },
  modules: {
  }
})