From 319b0d3c4496bc8812abec66cfb2f747e70d3d15 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Fri, 4 Oct 2019 04:11:40 +0300 Subject: [PATCH] Fix dispatching FetchReports and FetchUserStatuses from status module --- src/store/modules/status.js | 16 ++++++-- src/store/modules/userProfile.js | 41 +++++++++++-------- .../reports/components/GroupedReport.vue | 2 +- src/views/reports/components/Report.vue | 2 +- src/views/status/Status.vue | 19 ++++++++- src/views/users/show.vue | 23 ++++++----- 6 files changed, 68 insertions(+), 35 deletions(-) diff --git a/src/store/modules/status.js b/src/store/modules/status.js index a287f94b..15d1f1f7 100644 --- a/src/store/modules/status.js +++ b/src/store/modules/status.js @@ -2,13 +2,21 @@ import { changeStatusScope, deleteStatus } from '@/api/status' const status = { actions: { - async ChangeStatusScope({ dispatch, getters, state }, { statusId, isSensitive, visibility }) { + async ChangeStatusScope({ dispatch, getters }, { statusId, isSensitive, visibility, reportCurrentPage, userId, godmode }) { await changeStatusScope(statusId, isSensitive, visibility, getters.authHost, getters.token) - dispatch('FetchReports', state.currentPage) + if (reportCurrentPage !== 0) { + dispatch('FetchReports', reportCurrentPage) + } else if (userId.length > 0) { + dispatch('FetchUserStatuses', { userId, godmode }) + } }, - async DeleteStatus({ dispatch, getters, state }, { statusId }) { + async DeleteStatus({ dispatch, getters }, { statusId, reportCurrentPage, userId, godmode }) { await deleteStatus(statusId, getters.authHost, getters.token) - dispatch('FetchReports', state.currentPage) + if (reportCurrentPage !== 0) { + dispatch('FetchReports', reportCurrentPage) + } else if (userId.length > 0) { + dispatch('FetchUserStatuses', { userId, godmode }) + } } } } diff --git a/src/store/modules/userProfile.js b/src/store/modules/userProfile.js index 2dd656e6..5a7e4394 100644 --- a/src/store/modules/userProfile.js +++ b/src/store/modules/userProfile.js @@ -2,33 +2,42 @@ import { fetchUser, fetchUserStatuses } from '@/api/users' const userProfile = { state: { + statuses: [], + statusesLoading: true, user: {}, - loading: true, - statuses: [] + userProfileLoading: true }, mutations: { + SET_STATUSES: (state, statuses) => { + state.statuses = statuses + }, + SET_STATUSES_LOADING: (state, status) => { + state.statusesLoading = status + }, SET_USER: (state, user) => { state.user = user }, - SET_LOADING: (state, status) => { - state.loading = status - }, - SET_STATUSES: (state, statuses) => { - state.statuses = statuses + SET_USER_PROFILE_LOADING: (state, status) => { + state.userProfileLoading = status } }, actions: { - async FetchData({ commit, getters }, { id, godmode }) { - commit('SET_LOADING', true) - - const [userResponse, statusesResponse] = await Promise.all([ - fetchUser(id, getters.authHost, getters.token), - fetchUserStatuses(id, getters.authHost, godmode, getters.token) - ]) + async FetchUserProfile({ commit, dispatch, getters }, { userId, godmode }) { + commit('SET_USER_PROFILE_LOADING', true) + const userResponse = await fetchUser(userId, getters.authHost, getters.token) commit('SET_USER', userResponse.data) - commit('SET_STATUSES', statusesResponse.data) - commit('SET_LOADING', false) + commit('SET_USER_PROFILE_LOADING', false) + + dispatch('FetchUserStatuses', { userId, godmode }) + }, + async FetchUserStatuses({ commit, getters }, { userId, godmode }) { + commit('SET_STATUSES_LOADING', true) + + const statuses = await fetchUserStatuses(userId, getters.authHost, godmode, getters.token) + + commit('SET_STATUSES', statuses.data) + commit('SET_STATUSES_LOADING', false) } } } diff --git a/src/views/reports/components/GroupedReport.vue b/src/views/reports/components/GroupedReport.vue index 43d153f6..dcad3ad9 100644 --- a/src/views/reports/components/GroupedReport.vue +++ b/src/views/reports/components/GroupedReport.vue @@ -41,7 +41,7 @@
{{ $t('reports.reportedStatus') }}:
- +
diff --git a/src/views/reports/components/Report.vue b/src/views/reports/components/Report.vue index 76313a91..74e2ae88 100644 --- a/src/views/reports/components/Report.vue +++ b/src/views/reports/components/Report.vue @@ -58,7 +58,7 @@
- +
diff --git a/src/views/status/Status.vue b/src/views/status/Status.vue index e79b5a80..c4a3d8df 100644 --- a/src/views/status/Status.vue +++ b/src/views/status/Status.vue @@ -104,6 +104,21 @@ export default { status: { type: Object, required: true + }, + page: { + type: Number, + required: false, + default: 0 + }, + userId: { + type: String, + required: false, + default: '' + }, + godmode: { + type: Boolean, + required: false, + default: false } }, data() { @@ -116,7 +131,7 @@ export default { return str.charAt(0).toUpperCase() + str.slice(1) }, changeStatus(statusId, isSensitive, visibility) { - this.$store.dispatch('ChangeStatusScope', { statusId, isSensitive, visibility }) + this.$store.dispatch('ChangeStatusScope', { statusId, isSensitive, visibility, reportCurrentPage: this.page, userId: this.userId, godmode: this.godmode }) }, deleteStatus(statusId) { this.$confirm('Are you sure you want to delete this status?', 'Warning', { @@ -124,7 +139,7 @@ export default { cancelButtonText: 'Cancel', type: 'warning' }).then(() => { - this.$store.dispatch('DeleteStatus', { statusId }) + this.$store.dispatch('DeleteStatus', { statusId, reportCurrentPage: this.page, userId: this.userId, godmode: this.godmode }) this.$message({ type: 'success', message: 'Delete completed' diff --git a/src/views/users/show.vue b/src/views/users/show.vue index 829f7ebd..82eda5bb 100644 --- a/src/views/users/show.vue +++ b/src/views/users/show.vue @@ -1,5 +1,5 @@