From a8799cf5408410389181cf3c9ef99443710e155d Mon Sep 17 00:00:00 2001 From: "Alexis Jr. Banaag" Date: Thu, 23 Apr 2020 00:24:47 +0800 Subject: [PATCH 1/5] feat: implement modules --- src/store/index.js | 36 ++++++---------------------------- src/store/modules/countries.js | 23 ++++++++++++++++++++++ src/store/modules/stats.js | 23 ++++++++++++++++++++++ src/views/Dashboard.vue | 22 ++++++++++++--------- 4 files changed, 65 insertions(+), 39 deletions(-) create mode 100644 src/store/modules/countries.js create mode 100644 src/store/modules/stats.js diff --git a/src/store/index.js b/src/store/index.js index 6dff675..dbee5f6 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,37 +1,13 @@ import Vue from 'vue' import Vuex from 'vuex' -import CovidService from '@/services/covid.services' +import * as countries from './modules/countries' +import * as stats from './modules/stats' Vue.use(Vuex) export default new Vuex.Store({ - state: { - countries: [], - overviewStats: {} - }, - mutations: { - SET_COUNTRIES(state, data) { - state.countries = data - }, - SET_OVERVIEW_STATS(state, data) { - state.overviewStats = data - } - }, - actions: { - async fetchCountries({ commit }, filter) { - const { data } = await CovidService.fetchCountries(filter) - - if (data != null) { - commit('SET_COUNTRIES', data) - } - }, - async fetchOverviewStats({ commit }) { - const { data } = await CovidService.fetchWorldWide() - - if (data != null) { - commit('SET_OVERVIEW_STATS', data) - } - } - }, - modules: {} + modules: { + countries, + stats + } }) diff --git a/src/store/modules/countries.js b/src/store/modules/countries.js new file mode 100644 index 0000000..df03d31 --- /dev/null +++ b/src/store/modules/countries.js @@ -0,0 +1,23 @@ +import CovidService from '@/services/covid.services' + +export const namespaced = true + +export const state = { + countries: [] +} + +export const mutations = { + SET_COUNTRIES(state, data) { + state.countries = data + } +} + +export const actions = { + async fetchCountries({ commit }, filter) { + const { data } = await CovidService.fetchCountries(filter) + + if (data != null) { + commit('SET_COUNTRIES', data) + } + } +} diff --git a/src/store/modules/stats.js b/src/store/modules/stats.js new file mode 100644 index 0000000..0bddbd2 --- /dev/null +++ b/src/store/modules/stats.js @@ -0,0 +1,23 @@ +import CovidService from '@/services/covid.services' + +export const namespaced = true + +export const state = { + overview: {} +} + +export const mutations = { + SET_OVERVIEW_STATS(state, data) { + state.overview = data + } +} + +export const actions = { + async fetchOverviewStats({ commit }) { + const { data } = await CovidService.fetchWorldWide() + + if (data != null) { + commit('SET_OVERVIEW_STATS', data) + } + } +} diff --git a/src/views/Dashboard.vue b/src/views/Dashboard.vue index c64ff44..796b00f 100644 --- a/src/views/Dashboard.vue +++ b/src/views/Dashboard.vue @@ -23,7 +23,7 @@ import OverviewCard from '@/components/OverviewCard.vue' import CountriesList from '@/components/CountriesList.vue' import { formatNumber } from '@/common/helper.js' -import { mapState } from 'vuex' +import { mapState, mapActions } from 'vuex' export default { components: { @@ -31,15 +31,19 @@ export default { CountriesList }, created() { - this.$store.dispatch('fetchCountries', 'cases') - this.$store.dispatch('fetchOverviewStats') + this.fetchCountries('cases') + this.fetchOverviewStats() }, computed: mapState({ - countries: state => state.countries.slice(0, 10), - totalCases: state => formatNumber(state.overviewStats.cases), - newCases: state => formatNumber(state.overviewStats.todayCases), - totalRecoveries: state => formatNumber(state.overviewStats.recovered), - totalDeaths: state => formatNumber(state.overviewStats.deaths) - }) + countries: state => state.countries.countries.slice(0, 10), + totalCases: state => formatNumber(state.stats.overview.cases), + newCases: state => formatNumber(state.stats.overview.todayCases), + totalRecoveries: state => formatNumber(state.stats.overview.recovered), + totalDeaths: state => formatNumber(state.stats.overview.deaths) + }), + methods: { + ...mapActions('countries', ['fetchCountries']), + ...mapActions('stats', ['fetchOverviewStats']) + } } From 19114fa0156c8bd4515b14d022f0df3af9ec89bf Mon Sep 17 00:00:00 2001 From: "Alexis Jr. Banaag" Date: Sat, 25 Apr 2020 02:12:02 +0800 Subject: [PATCH 2/5] feat: integrate vuetify, add reusable header --- package.json | 1 + src/App.vue | 23 ++++++++++++++--------- src/components/Header.vue | 12 ++++++++++++ src/plugins/vuetify.js | 7 ++++++- src/views/Countries.vue | 13 ++++++++----- src/views/Dashboard.vue | 20 +++++++++++--------- yarn.lock | 5 +++++ 7 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 src/components/Header.vue diff --git a/package.json b/package.json index f7bbf27..3fabee1 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "vuex": "^3.1.3" }, "devDependencies": { + "@fortawesome/fontawesome-free": "^5.13.0", "@vue/cli-plugin-babel": "~4.3.0", "@vue/cli-plugin-eslint": "~4.3.0", "@vue/cli-plugin-router": "~4.3.0", diff --git a/src/App.vue b/src/App.vue index c35d9f8..57306a0 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,9 +1,19 @@ - + diff --git a/src/store/modules/countries.js b/src/store/modules/countries.js index 1669d6a..a443e78 100644 --- a/src/store/modules/countries.js +++ b/src/store/modules/countries.js @@ -4,7 +4,7 @@ export const namespaced = true export const state = { countries: [], - selected: {} + selected: null } export const mutations = { @@ -24,6 +24,13 @@ export const actions = { commit('SET_COUNTRIES', data) } }, + async fetchByCountry({ commit }, code) { + const { data } = await CovidService.fetchByCountry(code) + + if (data != null) { + commit('SET_SELECTED_COUNTRY', data) + } + }, setSelectedCountry({ commit }, country) { commit('SET_SELECTED_COUNTRY', country) } diff --git a/src/views/Countries.vue b/src/views/Countries.vue index 8b46683..268e4af 100644 --- a/src/views/Countries.vue +++ b/src/views/Countries.vue @@ -3,19 +3,22 @@

Countries

- + @@ -25,11 +28,6 @@ import CountriesList from '@/components/CountriesList.vue' import CountryInfo from '@/components/CountryInfo.vue' import { mapState, mapActions } from 'vuex' export default { - data() { - return { - isVisible: false - } - }, components: { CountriesList, CountryInfo @@ -43,10 +41,9 @@ export default { }), methods: { handleSelectedCountry(data) { - this.isVisible = !this.isVisible - this.setSelectedCountry(data) + this.fetchByCountry(data.countryInfo.iso2) }, - ...mapActions('countries', ['fetchCountries', 'setSelectedCountry']) + ...mapActions('countries', ['fetchCountries', 'fetchByCountry']) } } From 11904a178f4b7d111c4b354dae94fcef89db11d0 Mon Sep 17 00:00:00 2001 From: "Alexis Jr. Banaag" Date: Sun, 26 Apr 2020 17:51:54 +0800 Subject: [PATCH 5/5] docs: bump version --- .travis.yml | 3 ++- package.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index cbd49a9..bb0dece 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,4 +12,5 @@ deploy: github_token: $GITHUB_TOKEN local_dir: dist on: - branch: master \ No newline at end of file + branch: master + tags: true \ No newline at end of file diff --git a/package.json b/package.json index 3fabee1..d149b82 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "covid-vue", - "version": "0.2.0", + "version": "0.5.0", "private": true, "scripts": { "serve": "vue-cli-service serve",