From 180f02f7a26a80c4f87c7c51be53b6faeb55019b Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sat, 18 May 2019 01:47:20 +0300 Subject: [PATCH] Show fetched reports --- package.json | 1 + src/api/reports.js | 30 +++++++----- src/store/modules/reports.js | 34 ++++++------- src/store/modules/users.js | 3 -- src/views/reports/components/TimelineItem.vue | 49 ++++++++++++++----- src/views/reports/index.vue | 2 +- yarn.lock | 5 ++ 7 files changed, 80 insertions(+), 44 deletions(-) diff --git a/package.json b/package.json index 36d058b6..9848fecd 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "jszip": "3.1.5", "lodash": "^4.17.11", "lodash.debounce": "^4.0.8", + "moment": "^2.24.0", "normalize.css": "7.0.0", "nprogress": "0.2.0", "screenfull": "4.0.0", diff --git a/src/api/reports.js b/src/api/reports.js index c4d6e84a..e9687a01 100644 --- a/src/api/reports.js +++ b/src/api/reports.js @@ -1,14 +1,22 @@ -import { reports } from './reportsData' +import request from '@/utils/request' +import { getToken } from '@/utils/auth' +import { baseName } from './utils' -export function fetchReports(index, size) { - const response = reports.slice(index, index + size) - return response +export async function fetchReports(authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/reports`, + method: 'get', + headers: authHeaders(token) + }) } -export function deleteNote(reportId, noteId) { - const updatedNotes = reports - .find(report => report.id === reportId) - .notes - .filter(note => note.id !== noteId) - return updatedNotes -} +// export function deleteNote(reportId, noteId) { +// const updatedNotes = reports +// .find(report => report.id === reportId) +// .notes +// .filter(note => note.id !== noteId) +// return updatedNotes +// } + +const authHeaders = (token) => token ? { 'Authorization': `Bearer ${getToken()}` } : {} diff --git a/src/store/modules/reports.js b/src/store/modules/reports.js index f6d9fc16..01d48027 100644 --- a/src/store/modules/reports.js +++ b/src/store/modules/reports.js @@ -1,4 +1,4 @@ -import { fetchReports, deleteNote } from '@/api/reports' +import { fetchReports } from '@/api/reports' const reports = { state: { @@ -22,27 +22,27 @@ const reports = { } }, actions: { - async FetchReports({ commit, state, getters }) { + async FetchReports({ commit, getters }) { commit('SET_LOADING', true) - const response = fetchReports(state.indexOfLastShownReport, state.size) + const response = await fetchReports(getters.authHost, getters.token) - commit('SET_REPORTS', response) + commit('SET_REPORTS', response.data.reports) commit('SET_INDEX') commit('SET_LOADING', false) - }, - async AddNote({ commit, state, getters }, { reportId, note }) { - const report = state.fetchedReports.find(report => report.id === reportId) - report.notes = [...report.notes, note] - const reportIndex = state.fetchedReports.findIndex(report => report.id === reportId) - commit('SET_REPORT', { reportIndex, report }) - }, - async DeleteNote({ commit, state }, { reportId, noteId }) { - const response = deleteNote(reportId, noteId) - const report = state.fetchedReports.find(report => report.id === reportId) - report.notes = response - const reportIndex = state.fetchedReports.findIndex(report => report.id === reportId) - commit('SET_REPORT', { reportIndex, report }) } + // async AddNote({ commit, state, getters }, { reportId, note }) { + // const report = state.fetchedReports.find(report => report.id === reportId) + // report.notes = [...report.notes, note] + // const reportIndex = state.fetchedReports.findIndex(report => report.id === reportId) + // commit('SET_REPORT', { reportIndex, report }) + // }, + // async DeleteNote({ commit, state }, { reportId, noteId }) { + // const response = deleteNote(reportId, noteId) + // const report = state.fetchedReports.find(report => report.id === reportId) + // report.notes = response + // const reportIndex = state.fetchedReports.findIndex(report => report.id === reportId) + // commit('SET_REPORT', { reportIndex, report }) + // } } } diff --git a/src/store/modules/users.js b/src/store/modules/users.js index 1321aa65..c5278256 100644 --- a/src/store/modules/users.js +++ b/src/store/modules/users.js @@ -72,9 +72,6 @@ const users = { commit('SWAP_USER', updatedUser) }, async FetchUsers({ commit, state, getters }, { page }) { - const filters = Object.keys(state.filters).filter(filter => state.filters[filter]).join() - const response = await fetchUsers(filters, getters.authHost, getters.token, page) - commit('SET_LOADING', true) const filters = Object.keys(state.filters).filter(filter => state.filters[filter]).join() diff --git a/src/views/reports/components/TimelineItem.vue b/src/views/reports/components/TimelineItem.vue index 60ab7aa9..d6a65bb1 100644 --- a/src/views/reports/components/TimelineItem.vue +++ b/src/views/reports/components/TimelineItem.vue @@ -1,19 +1,23 @@