diff --git a/src/api/status.js b/src/api/status.js index ab9334e5..676cd9dc 100644 --- a/src/api/status.js +++ b/src/api/status.js @@ -21,7 +21,7 @@ export async function deleteStatus(id, authHost, token) { }) } -export async function fetchStatusesByInstance(instance, authHost, token, pageSize, page = 1) { +export async function fetchStatusesByInstance({ instance, authHost, token, pageSize, page }) { return await request({ baseURL: baseName(authHost), url: `/api/pleroma/admin/instances/${instance}/statuses?page=${page}&page_size=${pageSize}`, diff --git a/src/store/modules/status.js b/src/store/modules/status.js index e937ed5c..a05b69f2 100644 --- a/src/store/modules/status.js +++ b/src/store/modules/status.js @@ -3,9 +3,20 @@ import { changeStatusScope, deleteStatus, fetchStatusesByInstance } from '@/api/ const status = { state: { fetchedStatuses: [], - loading: false + loading: false, + statusesByInstance: { + selectedInstance: '', + page: 1, + pageSize: 30 + } }, mutations: { + CHANGE_PAGE: (state, page) => { + state.statusesByInstance.page = page + }, + CHANGE_SELECTED_INSTANCE: (state, instance) => { + state.statusesByInstance.selectedInstance = instance + }, SET_STATUSES: (state, statuses) => { state.fetchedStatuses = statuses }, @@ -37,19 +48,39 @@ const status = { dispatch('FetchGroupedReports') } }, - async FetchStatusesByInstance({ commit, getters }, { instance, page, pageSize }) { + async FetchStatusesByInstance({ commit, getters, state }) { commit('SET_LOADING', true) - const statuses = await fetchStatusesByInstance(instance, getters.authHost, getters.token, pageSize, page) + const statuses = await fetchStatusesByInstance( + { + instance: state.statusesByInstance.selectedInstance, + authHost: getters.authHost, + token: getters.token, + pageSize: state.statusesByInstance.pageSize, + page: state.statusesByInstance.page + }) commit('SET_STATUSES', statuses.data) commit('SET_LOADING', false) }, - async FetchStatusesPageByInstance({ commit, getters }, { instance, page, pageSize }) { + async FetchStatusesPageByInstance({ commit, getters, state }) { commit('SET_LOADING', true) - const statuses = await fetchStatusesByInstance(instance, getters.authHost, getters.token, pageSize, page) + const statuses = await fetchStatusesByInstance( + { + instance: state.statusesByInstance.selectedInstance, + authHost: getters.authHost, + token: getters.token, + pageSize: state.statusesByInstance.pageSize, + page: state.statusesByInstance.page + }) commit('PUSH_STATUSES', statuses.data) commit('SET_LOADING', false) + }, + HandleFilterChange({ commit }, instance) { + commit('CHANGE_SELECTED_INSTANCE', instance) + }, + HandlePageChange({ commit }, page) { + commit('CHANGE_PAGE', page) } } } diff --git a/src/views/statuses/index.vue b/src/views/statuses/index.vue index a304ee2b..3789d6a9 100644 --- a/src/views/statuses/index.vue +++ b/src/views/statuses/index.vue @@ -22,7 +22,11 @@ @apply-action="clearSelection"/>