From d383bd08f0266406d4b0c9eb68c76e62c9d4a460 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 19 Mar 2021 16:06:10 +0100 Subject: feat: get emails --- src/store.js | 22 ++++++++++++++++++++++ src/views/Home.vue | 6 +++++- 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/store.js b/src/store.js index 9080bd0..888add2 100644 --- a/src/store.js +++ b/src/store.js @@ -7,16 +7,24 @@ export default new Vuex.Store({ state: { api: process.env.VUE_APP_BACKEND_URL, commits: [], + emails: {}, }, get: { commits: state => { return state.commits }, + emails: state => { + return state.emails + }, }, mutations: { 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 @@ -26,6 +34,20 @@ export default new Vuex.Store({ commit('load_commits', await response.json()); }) }, + // 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: { } diff --git a/src/views/Home.vue b/src/views/Home.vue index 28da86b..e507ef8 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -15,11 +15,15 @@ export default { }, mounted() { this.$store.dispatch('get_commits'); + this.$store.dispatch('get_emails'); }, computed: { commits: () => { return this.$store.get.commits; - } + }, + emails: () => { + return this.$store.get.emails; + }, } } -- cgit v1.2.3-18-g5258