forked from AkkomaGang/admin-fe
Move statuses state from component data to module
This commit is contained in:
parent
74018751e8
commit
4566725a4e
3 changed files with 62 additions and 23 deletions
|
@ -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({
|
return await request({
|
||||||
baseURL: baseName(authHost),
|
baseURL: baseName(authHost),
|
||||||
url: `/api/pleroma/admin/instances/${instance}/statuses?page=${page}&page_size=${pageSize}`,
|
url: `/api/pleroma/admin/instances/${instance}/statuses?page=${page}&page_size=${pageSize}`,
|
||||||
|
|
|
@ -3,9 +3,20 @@ import { changeStatusScope, deleteStatus, fetchStatusesByInstance } from '@/api/
|
||||||
const status = {
|
const status = {
|
||||||
state: {
|
state: {
|
||||||
fetchedStatuses: [],
|
fetchedStatuses: [],
|
||||||
loading: false
|
loading: false,
|
||||||
|
statusesByInstance: {
|
||||||
|
selectedInstance: '',
|
||||||
|
page: 1,
|
||||||
|
pageSize: 30
|
||||||
|
}
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
|
CHANGE_PAGE: (state, page) => {
|
||||||
|
state.statusesByInstance.page = page
|
||||||
|
},
|
||||||
|
CHANGE_SELECTED_INSTANCE: (state, instance) => {
|
||||||
|
state.statusesByInstance.selectedInstance = instance
|
||||||
|
},
|
||||||
SET_STATUSES: (state, statuses) => {
|
SET_STATUSES: (state, statuses) => {
|
||||||
state.fetchedStatuses = statuses
|
state.fetchedStatuses = statuses
|
||||||
},
|
},
|
||||||
|
@ -37,19 +48,39 @@ const status = {
|
||||||
dispatch('FetchGroupedReports')
|
dispatch('FetchGroupedReports')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async FetchStatusesByInstance({ commit, getters }, { instance, page, pageSize }) {
|
async FetchStatusesByInstance({ commit, getters, state }) {
|
||||||
commit('SET_LOADING', true)
|
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_STATUSES', statuses.data)
|
||||||
commit('SET_LOADING', false)
|
commit('SET_LOADING', false)
|
||||||
},
|
},
|
||||||
async FetchStatusesPageByInstance({ commit, getters }, { instance, page, pageSize }) {
|
async FetchStatusesPageByInstance({ commit, getters, state }) {
|
||||||
commit('SET_LOADING', true)
|
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('PUSH_STATUSES', statuses.data)
|
||||||
commit('SET_LOADING', false)
|
commit('SET_LOADING', false)
|
||||||
|
},
|
||||||
|
HandleFilterChange({ commit }, instance) {
|
||||||
|
commit('CHANGE_SELECTED_INSTANCE', instance)
|
||||||
|
},
|
||||||
|
HandlePageChange({ commit }, page) {
|
||||||
|
commit('CHANGE_PAGE', page)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,11 @@
|
||||||
@apply-action="clearSelection"/>
|
@apply-action="clearSelection"/>
|
||||||
</div>
|
</div>
|
||||||
<div v-for="status in statuses" :key="status.id" class="status-container">
|
<div v-for="status in statuses" :key="status.id" class="status-container">
|
||||||
<status :status="status" :show-checkbox="isDesktop" @status-selection="handleStatusSelection" />
|
<status
|
||||||
|
:status="status"
|
||||||
|
:show-checkbox="isDesktop"
|
||||||
|
:statuses-args="{ instance: selectedInstance, page, pageSize }"
|
||||||
|
@status-selection="handleStatusSelection" />
|
||||||
</div>
|
</div>
|
||||||
<div v-if="statuses.length > 0" class="statuses-pagination">
|
<div v-if="statuses.length > 0" class="statuses-pagination">
|
||||||
<el-button @click="handleLoadMore">{{ $t('statuses.loadMore') }}</el-button>
|
<el-button @click="handleLoadMore">{{ $t('statuses.loadMore') }}</el-button>
|
||||||
|
@ -43,10 +47,7 @@ export default {
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
selectedInstance: '',
|
selectedUsers: []
|
||||||
selectedUsers: [],
|
|
||||||
page: 1,
|
|
||||||
pageSize: 30
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -59,27 +60,34 @@ export default {
|
||||||
},
|
},
|
||||||
loadingPeers() {
|
loadingPeers() {
|
||||||
return this.$store.state.peers.loading
|
return this.$store.state.peers.loading
|
||||||
|
},
|
||||||
|
page() {
|
||||||
|
return this.$store.state.status.statusesByInstance.page
|
||||||
|
},
|
||||||
|
pageSize() {
|
||||||
|
return this.$store.state.status.statusesByInstance.pageSize
|
||||||
|
},
|
||||||
|
selectedInstance: {
|
||||||
|
get() {
|
||||||
|
return this.$store.state.status.statusesByInstance.selectedInstance
|
||||||
|
},
|
||||||
|
set(instance) {
|
||||||
|
this.$store.dispatch('HandleFilterChange', instance)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
|
||||||
},
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$store.dispatch('FetchPeers')
|
this.$store.dispatch('FetchPeers')
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleFilterChange(instance) {
|
handleFilterChange() {
|
||||||
this.page = 1
|
this.$store.dispatch('HandlePageChange', 1)
|
||||||
|
this.$store.dispatch('FetchStatusesByInstance')
|
||||||
this.$store.dispatch('FetchStatusesByInstance', { instance, page: this.page, pageSize: this.pageSize })
|
|
||||||
},
|
},
|
||||||
handleLoadMore() {
|
handleLoadMore() {
|
||||||
this.page = this.page + 1
|
this.$store.dispatch('HandlePageChange', this.page + 1)
|
||||||
|
|
||||||
this.$store.dispatch('FetchStatusesPageByInstance', {
|
this.$store.dispatch('FetchStatusesPageByInstance')
|
||||||
instance: this.selectedInstance,
|
|
||||||
page: this.page,
|
|
||||||
pageSize: this.pageSize
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
clearSelection() {
|
clearSelection() {
|
||||||
// TODO
|
// TODO
|
||||||
|
|
Loading…
Reference in a new issue