Add api function and module action for fetching grouped reports

This commit is contained in:
Angelina Filippova 2019-10-15 19:27:22 +02:00
parent e38dbbf4c7
commit 6258334307
3 changed files with 25 additions and 1 deletions

View file

@ -24,4 +24,13 @@ export async function fetchReports(filter, page, pageSize, authHost, token) {
})
}
export async function fetchGroupedReports(authHost, token) {
return await request({
baseURL: baseName(authHost),
url: `/api/pleroma/admin/grouped_reports`,
method: 'get',
headers: authHeaders(token)
})
}
const authHeaders = (token) => token ? { 'Authorization': `Bearer ${getToken()}` } : {}

View file

@ -1,8 +1,9 @@
import { changeState, fetchReports } from '@/api/reports'
import { changeState, fetchReports, fetchGroupedReports } from '@/api/reports'
const reports = {
state: {
fetchedReports: [],
fetchedGroupedReports: [],
totalReportsCount: 0,
currentPage: 1,
pageSize: 50,
@ -23,6 +24,9 @@ const reports = {
SET_REPORTS: (state, reports) => {
state.fetchedReports = reports
},
SET_GROUPED_REPORTS: (state, reports) => {
state.fetchedGroupedReports = reports
},
SET_REPORTS_COUNT: (state, total) => {
state.totalReportsCount = total
},
@ -51,6 +55,14 @@ const reports = {
commit('SET_PAGE', page)
commit('SET_LOADING', false)
},
async FetchGroupedReports({ commit, getters }) {
commit('SET_LOADING', true)
const { data } = await fetchGroupedReports(getters.authHost, getters.token)
console.log(reports)
commit('SET_GROUPED_REPORTS', data.reports)
commit('SET_LOADING', false)
},
SetFilter({ commit }, filter) {
commit('SET_REPORTS_FILTER', filter)
},

View file

@ -70,6 +70,9 @@ export default {
required: true
}
},
mounted() {
this.$store.dispatch('FetchGroupedReports', 1)
},
methods: {
changeAllReports(reportState, groupOfReports) {
console.log(groupOfReports)