From 3df6738bc703290a78ebe758a8114a778a857eca Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Tue, 14 Jul 2020 19:19:42 +0300 Subject: [PATCH] Create separate constant in state and action for open reports count --- src/store/modules/reports.js | 20 +++++++++++++++---- .../layout/components/Sidebar/SidebarItem.vue | 2 +- src/views/layout/components/Sidebar/index.vue | 3 +-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/store/modules/reports.js b/src/store/modules/reports.js index 6a56dedb..1f6ae44f 100644 --- a/src/store/modules/reports.js +++ b/src/store/modules/reports.js @@ -2,12 +2,13 @@ import { changeState, fetchReports, createNote, deleteNote } from '@/api/reports const reports = { state: { - fetchedReports: [], - totalReportsCount: 0, currentPage: 1, + fetchedReports: [], + loading: true, + openReportsCount: 0, pageSize: 50, stateFilter: '', - loading: true + totalReportsCount: 0 }, mutations: { SET_LAST_REPORT_ID: (state, id) => { @@ -16,6 +17,9 @@ const reports = { SET_LOADING: (state, status) => { state.loading = status }, + SET_OPEN_REPORTS_COUNT: (state, total) => { + state.openReportsCount = total + }, SET_PAGE: (state, page) => { state.currentPage = page }, @@ -30,7 +34,7 @@ const reports = { } }, actions: { - async ChangeReportState({ commit, getters, state }, reportsData) { + async ChangeReportState({ commit, dispatch, getters, state }, reportsData) { changeState(reportsData, getters.authHost, getters.token) const updatedReports = state.fetchedReports.map(report => { @@ -39,6 +43,7 @@ const reports = { }) commit('SET_REPORTS', updatedReports) + dispatch('FetchOpenReportsCount') }, ClearFetchedReports({ commit }) { commit('SET_REPORTS', []) @@ -52,6 +57,13 @@ const reports = { commit('SET_PAGE', page) commit('SET_LOADING', false) }, + async FetchOpenReportsCount({ commit, getters, state }) { + commit('SET_LOADING', true) + const { data } = await fetchReports('open', state.currentPage, state.pageSize, getters.authHost, getters.token) + + commit('SET_OPEN_REPORTS_COUNT', data.total) + commit('SET_LOADING', false) + }, SetReportsFilter({ commit }, filter) { commit('SET_REPORTS_FILTER', filter) }, diff --git a/src/views/layout/components/Sidebar/SidebarItem.vue b/src/views/layout/components/Sidebar/SidebarItem.vue index c81a33ce..7451ada2 100644 --- a/src/views/layout/components/Sidebar/SidebarItem.vue +++ b/src/views/layout/components/Sidebar/SidebarItem.vue @@ -85,7 +85,7 @@ export default { return this.basePath === '/invites' ? this.$store.state.app.invitesEnabled : true }, normalizedReportsCount() { - return numeral(this.$store.state.reports.totalReportsCount).format('0a') + return numeral(this.$store.state.reports.openReportsCount).format('0a') } }, methods: { diff --git a/src/views/layout/components/Sidebar/index.vue b/src/views/layout/components/Sidebar/index.vue index 369f321d..e52ae6b6 100644 --- a/src/views/layout/components/Sidebar/index.vue +++ b/src/views/layout/components/Sidebar/index.vue @@ -33,8 +33,7 @@ export default { } }, mounted() { - this.$store.dispatch('SetReportsFilter', 'open') - this.$store.dispatch('FetchReports', 1) + this.$store.dispatch('FetchOpenReportsCount') } }