From 6ccffd97283b4d50b2cc5f8d54c53cd858a4d2f0 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sat, 28 Sep 2019 01:24:51 +0300 Subject: [PATCH] Fetch reports after changing and deleting status --- src/store/modules/reports.js | 26 ++++------------- src/views/reports/components/Report.vue | 7 ++++- src/views/reports/components/Statuses.vue | 35 +++++++++++------------ 3 files changed, 27 insertions(+), 41 deletions(-) diff --git a/src/store/modules/reports.js b/src/store/modules/reports.js index a699a22a..8ff3a909 100644 --- a/src/store/modules/reports.js +++ b/src/store/modules/reports.js @@ -28,33 +28,17 @@ const reports = { const updatedReports = state.fetchedReports.map(report => report.id === reportId ? data : report) commit('SET_REPORTS', updatedReports) }, - async ChangeStatusScope({ commit, getters, state }, { statusId, isSensitive, visibility, reportId }) { - const { data } = await changeStatusScope(statusId, isSensitive, visibility, getters.authHost, getters.token) - const updatedReports = state.fetchedReports.map(report => { - if (report.id === reportId) { - const statuses = report.statuses.map(status => status.id === statusId ? data : status) - return { ...report, statuses } - } else { - return report - } - }) - commit('SET_REPORTS', updatedReports) + async ChangeStatusScope({ dispatch, getters }, { statusId, isSensitive, visibility }) { + await changeStatusScope(statusId, isSensitive, visibility, getters.authHost, getters.token) + dispatch('FetchReports') }, ClearFetchedReports({ commit }) { commit('SET_REPORTS', []) commit('SET_LAST_REPORT_ID', '') }, - async DeleteStatus({ commit, getters, state }, { statusId, reportId }) { + async DeleteStatus({ dispatch, getters }, { statusId }) { deleteStatus(statusId, getters.authHost, getters.token) - const updatedReports = state.fetchedReports.map(report => { - if (report.id === reportId) { - const statuses = report.statuses.filter(status => status.id !== statusId) - return { ...report, statuses } - } else { - return report - } - }) - commit('SET_REPORTS', updatedReports) + dispatch('FetchReports') }, async FetchReports({ commit, getters, state }) { commit('SET_LOADING', true) diff --git a/src/views/reports/components/Report.vue b/src/views/reports/components/Report.vue index 6d07aded..418284d3 100644 --- a/src/views/reports/components/Report.vue +++ b/src/views/reports/components/Report.vue @@ -49,7 +49,9 @@
- + + +
@@ -87,6 +89,9 @@ export default { return 'primary' } }, + getStatusesTitle(statuses) { + return `Reported statuses: ${statuses.length} item(s)` + }, parseTimestamp(timestamp) { return moment(timestamp).format('L HH:mm') } diff --git a/src/views/reports/components/Statuses.vue b/src/views/reports/components/Statuses.vue index a385a700..c276af90 100644 --- a/src/views/reports/components/Statuses.vue +++ b/src/views/reports/components/Statuses.vue @@ -1,6 +1,6 @@