From c9d6402c3714cf832e1abb25e432447b8c1c71be Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sat, 25 May 2019 01:46:08 +0200 Subject: [PATCH] Add ability to delete status --- src/api/reports.js | 9 ++++++++ src/lang/en.js | 3 ++- src/store/modules/reports.js | 14 +++++++++++- src/views/reports/components/Statuses.vue | 22 +++++++++++++++++++ src/views/reports/components/TimelineItem.vue | 2 +- 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/api/reports.js b/src/api/reports.js index cfc8bd3c..c84a5bfd 100644 --- a/src/api/reports.js +++ b/src/api/reports.js @@ -22,6 +22,15 @@ export async function changeStatusScope(id, sensitive, visibility, authHost, tok }) } +export async function deleteStatus(id, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/statuses/${id}`, + method: 'delete', + headers: authHeaders(token) + }) +} + export async function fetchReports(limit, max_id, authHost, token) { return await request({ baseURL: baseName(authHost), diff --git a/src/lang/en.js b/src/lang/en.js index d2476cdf..53f13818 100644 --- a/src/lang/en.js +++ b/src/lang/en.js @@ -223,7 +223,8 @@ export default { public: 'Make status public', private: 'Make status private', unlisted: 'Make status unlisted', - sensitive: 'Sensitive' + sensitive: 'Sensitive', + deleteStatus: 'Delete status' }, reportsFilter: { inputPlaceholder: 'Select filter', diff --git a/src/store/modules/reports.js b/src/store/modules/reports.js index a432f63e..08bf1b68 100644 --- a/src/store/modules/reports.js +++ b/src/store/modules/reports.js @@ -1,4 +1,4 @@ -import { changeState, changeStatusScope, fetchReports, filterReports } from '@/api/reports' +import { changeState, changeStatusScope, deleteStatus, fetchReports, filterReports } from '@/api/reports' const reports = { state: { @@ -40,6 +40,18 @@ const reports = { }) commit('SET_REPORTS', updatedReports) }, + async DeleteStatus({ commit, getters, state }, { statusId, reportId }) { + 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) + }, async FetchReports({ commit, getters, state }) { commit('SET_LOADING', true) const response = await fetchReports(state.page_limit, state.idOfLastReport, getters.authHost, getters.token) diff --git a/src/views/reports/components/Statuses.vue b/src/views/reports/components/Statuses.vue index 44849793..7834615e 100644 --- a/src/views/reports/components/Statuses.vue +++ b/src/views/reports/components/Statuses.vue @@ -38,6 +38,10 @@ @click.native="changeStatus(status.id, status.sensitive, 'unlisted', report.id)"> {{ $t('reports.unlisted') }} + + {{ $t('reports.deleteStatus') }} + @@ -74,6 +78,24 @@ export default { changeStatus(statusId, isSensitive, visibility, reportId) { this.$store.dispatch('ChangeStatusScope', { statusId, isSensitive, visibility, reportId }) }, + deleteStatus(statusId, reportId) { + this.$confirm('Are you sure you want to delete this status?', 'Warning', { + confirmButtonText: 'OK', + cancelButtonText: 'Cancel', + type: 'warning' + }).then(() => { + this.$store.dispatch('DeleteStatus', { statusId, reportId }) + this.$message({ + type: 'success', + message: 'Delete completed' + }) + }).catch(() => { + this.$message({ + type: 'info', + message: 'Delete canceled' + }) + }) + }, getStatusesTitle(statuses) { return `Reported statuses: ${statuses.length} item(s)` }, diff --git a/src/views/reports/components/TimelineItem.vue b/src/views/reports/components/TimelineItem.vue index 65e19d6d..4dd021aa 100644 --- a/src/views/reports/components/TimelineItem.vue +++ b/src/views/reports/components/TimelineItem.vue @@ -21,7 +21,7 @@ Account: User's avatar {{ report.account.acct }}