Pagination

This commit is contained in:
Maxim Filippov 2019-11-15 12:54:33 +09:00
parent 6695226e12
commit f477dec059
5 changed files with 41 additions and 10 deletions

View file

@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added ### Added
- Emoji pack configuration - Emoji pack configuration
- Statuses page: fetch all statuses from a given instance
## [1.1.0] - 2019-09-15 ## [1.1.0] - 2019-09-15

View file

@ -21,10 +21,10 @@ export async function deleteStatus(id, authHost, token) {
}) })
} }
export async function fetchStatusesByInstance(instance, authHost, token) { export async function fetchStatusesByInstance(instance, authHost, token, pageSize, page = 1) {
return await request({ return await request({
baseURL: baseName(authHost), baseURL: baseName(authHost),
url: `/api/pleroma/admin/instances/${instance}/statuses`, url: `/api/pleroma/admin/instances/${instance}/statuses?page=${page}&page_size=${pageSize}`,
method: 'get', method: 'get',
headers: authHeaders(token) headers: authHeaders(token)
}) })

View file

@ -232,7 +232,8 @@ export default {
}, },
statuses: { statuses: {
statuses: 'Statuses', statuses: 'Statuses',
instanceFilter: 'Instance filter' instanceFilter: 'Instance filter',
loadMore: 'Load more'
}, },
userProfile: { userProfile: {
tags: 'Tags', tags: 'Tags',

View file

@ -9,6 +9,9 @@ const status = {
SET_STATUSES: (state, statuses) => { SET_STATUSES: (state, statuses) => {
state.fetchedStatuses = statuses state.fetchedStatuses = statuses
}, },
PUSH_STATUSES: (state, statuses) => {
state.fetchedStatuses = [...state.fetchedStatuses, ...statuses]
},
SET_LOADING: (state, status) => { SET_LOADING: (state, status) => {
state.loading = status state.loading = status
} }
@ -30,12 +33,19 @@ const status = {
dispatch('FetchUserStatuses', { userId, godmode }) dispatch('FetchUserStatuses', { userId, godmode })
} }
}, },
async FetchStatusesByInstance({ commit, getters }, instance) { async FetchStatusesByInstance({ commit, getters }, { instance, page, pageSize }) {
commit('SET_LOADING', true) commit('SET_LOADING', true)
const statuses = await fetchStatusesByInstance(instance, getters.authHost, getters.token) const statuses = await fetchStatusesByInstance(instance, getters.authHost, getters.token, pageSize, 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 }) {
commit('SET_LOADING', true)
const statuses = await fetchStatusesByInstance(instance, getters.authHost, getters.token, pageSize, page)
commit('PUSH_STATUSES', statuses.data)
commit('SET_LOADING', false)
} }
} }
} }

View file

@ -1,5 +1,5 @@
<template> <template>
<div v-if="!loading" class="statuses-container"> <div v-if="!loadingPeers" class="statuses-container">
<h1> <h1>
{{ $t('statuses.statuses') }} {{ $t('statuses.statuses') }}
</h1> </h1>
@ -13,6 +13,9 @@
</el-select> </el-select>
</div> </div>
<status v-for="status in statuses" :key="status.id" :status="status" /> <status v-for="status in statuses" :key="status.id" :status="status" />
<div v-if="statuses.length > 0" class="statuses-pagination">
<el-button @click="handleLoadMore">{{ $t('statuses.loadMore') }}</el-button>
</div>
</div> </div>
</template> </template>
@ -28,11 +31,12 @@ export default {
data() { data() {
return { return {
selectedInstance: '', selectedInstance: '',
page: 1 page: 1,
pageSize: 2
} }
}, },
computed: { computed: {
loading() { loadingPeers() {
return this.$store.state.peers.loading return this.$store.state.peers.loading
}, },
...mapGetters([ ...mapGetters([
@ -47,7 +51,18 @@ export default {
}, },
methods: { methods: {
handleFilterChange(instance) { handleFilterChange(instance) {
this.$store.dispatch('FetchStatusesByInstance', instance) this.page = 1
this.$store.dispatch('FetchStatusesByInstance', { instance, page: this.page, pageSize: this.pageSize })
},
handleLoadMore() {
this.page = this.page + 1
this.$store.dispatch('FetchStatusesPageByInstance', {
instance: this.selectedInstance,
page: this.page,
pageSize: this.pageSize
})
} }
} }
} }
@ -60,6 +75,10 @@ export default {
.filter-container { .filter-container {
margin: 22px 15px 15px 0; margin: 22px 15px 15px 0;
} }
.statuses-pagination {
padding: 15px 0;
text-align: center;
}
h1 { h1 {
margin: 22px 0 0 0; margin: 22px 0 0 0;
} }