From b7c83e06a96ec852c21432a13c652f371ce4d4d2 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Sat, 16 Nov 2019 18:31:19 +0900 Subject: [PATCH] Fix reports management --- CHANGELOG.md | 1 + src/api/__mocks__/reports.js | 3 +-- src/api/reports.js | 6 +++--- src/store/modules/reports.js | 8 ++++++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb2b750d..fee1cf9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - Show checkmarks when tag is applied +- Reports update (also, now it's optimistic) ## [1.2.0] - 2019-09-27 diff --git a/src/api/__mocks__/reports.js b/src/api/__mocks__/reports.js index a337df9a..e277d8df 100644 --- a/src/api/__mocks__/reports.js +++ b/src/api/__mocks__/reports.js @@ -23,8 +23,7 @@ export async function filterReports(filter, limit, max_id, authHost, token) { } export async function changeState(state, id, authHost, token) { - const report = reports.find(report => report.id === id) - return Promise.resolve({ data: { ...report, state }}) + return Promise.resolve({ data: '' }) } export async function changeStatusScope(id, sensitive, visibility, authHost, token) { diff --git a/src/api/reports.js b/src/api/reports.js index c84a5bfd..79833e40 100644 --- a/src/api/reports.js +++ b/src/api/reports.js @@ -5,10 +5,10 @@ import { baseName } from './utils' export async function changeState(state, id, authHost, token) { return await request({ baseURL: baseName(authHost), - url: `/api/pleroma/admin/reports/${id}`, - method: 'put', + url: `/api/pleroma/admin/reports`, + method: 'patch', headers: authHeaders(token), - data: { state } + data: { reports: [{ id, state }] } }) } diff --git a/src/store/modules/reports.js b/src/store/modules/reports.js index a699a22a..e44664f4 100644 --- a/src/store/modules/reports.js +++ b/src/store/modules/reports.js @@ -24,8 +24,12 @@ const reports = { }, actions: { async ChangeReportState({ commit, getters, state }, { reportState, reportId }) { - const { data } = await changeState(reportState, reportId, getters.authHost, getters.token) - const updatedReports = state.fetchedReports.map(report => report.id === reportId ? data : report) + changeState(reportState, reportId, getters.authHost, getters.token) + + const updatedReports = state.fetchedReports.map(report => { + return report.id === reportId ? { ...report, state: reportState } : report + }) + commit('SET_REPORTS', updatedReports) }, async ChangeStatusScope({ commit, getters, state }, { statusId, isSensitive, visibility, reportId }) {