Implement pagination for reports
This commit is contained in:
parent
f8562896b9
commit
1494f7fd9d
2 changed files with 12 additions and 10 deletions
|
@ -2,10 +2,10 @@ import request from '@/utils/request'
|
||||||
import { getToken } from '@/utils/auth'
|
import { getToken } from '@/utils/auth'
|
||||||
import { baseName } from './utils'
|
import { baseName } from './utils'
|
||||||
|
|
||||||
export async function fetchReports(authHost, token) {
|
export async function fetchReports(limit, max_id, authHost, token) {
|
||||||
return await request({
|
return await request({
|
||||||
baseURL: baseName(authHost),
|
baseURL: baseName(authHost),
|
||||||
url: `/api/pleroma/admin/reports`,
|
url: `/api/pleroma/admin/reports?limit=${limit}&max_id=${max_id}`,
|
||||||
method: 'get',
|
method: 'get',
|
||||||
headers: authHeaders(token)
|
headers: authHeaders(token)
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,8 +3,8 @@ import { fetchReports, toggleReportsFilter } from '@/api/reports'
|
||||||
const reports = {
|
const reports = {
|
||||||
state: {
|
state: {
|
||||||
fetchedReports: [],
|
fetchedReports: [],
|
||||||
indexOfLastShownReport: 0,
|
idOfLastReport: '',
|
||||||
size: 3,
|
page_limit: 5,
|
||||||
loading: true
|
loading: true
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
|
@ -17,17 +17,19 @@ const reports = {
|
||||||
SET_LOADING: (state, status) => {
|
SET_LOADING: (state, status) => {
|
||||||
state.loading = status
|
state.loading = status
|
||||||
},
|
},
|
||||||
SET_INDEX: (state) => {
|
SET_LAST_REPORT_ID: (state, id) => {
|
||||||
state.indexOfLastShownReport = state.indexOfLastShownReport + state.size
|
state.idOfLastReport = id
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async FetchReports({ commit, getters }) {
|
async FetchReports({ commit, state, getters }) {
|
||||||
commit('SET_LOADING', true)
|
commit('SET_LOADING', true)
|
||||||
const response = await fetchReports(getters.authHost, getters.token)
|
const response = await fetchReports(state.page_limit, state.idOfLastReport, getters.authHost, getters.token)
|
||||||
|
const reports = response.data.reports
|
||||||
|
const id = reports.length > 0 ? reports[reports.length - 1].id : state.idOfLastReport
|
||||||
|
|
||||||
commit('SET_REPORTS', response.data.reports)
|
commit('SET_REPORTS', reports)
|
||||||
commit('SET_INDEX')
|
commit('SET_LAST_REPORT_ID', id)
|
||||||
commit('SET_LOADING', false)
|
commit('SET_LOADING', false)
|
||||||
},
|
},
|
||||||
async ToggleReportsFilter({ getters }, filters) {
|
async ToggleReportsFilter({ getters }, filters) {
|
||||||
|
|
Loading…
Reference in a new issue