From f477dec059404698a57a77a98ba01715d9fc4758 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Fri, 15 Nov 2019 12:54:33 +0900 Subject: [PATCH] Pagination --- CHANGELOG.md | 3 ++- src/api/status.js | 4 ++-- src/lang/en.js | 3 ++- src/store/modules/status.js | 14 ++++++++++++-- src/views/statuses/index.vue | 27 +++++++++++++++++++++++---- 5 files changed, 41 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75553acf..017191a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added - Emoji pack configuration +- Statuses page: fetch all statuses from a given instance ## [1.1.0] - 2019-09-15 @@ -26,7 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - removes "Dashboard" from dropdown menu - makes all single selects clearable and allow to enter custom values in all multiple selects -- removes legacy activitypub accept_blocks setting +- removes legacy activitypub accept_blocks setting ### Fixed diff --git a/src/api/status.js b/src/api/status.js index 4b62da0b..ab9334e5 100644 --- a/src/api/status.js +++ b/src/api/status.js @@ -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({ baseURL: baseName(authHost), - url: `/api/pleroma/admin/instances/${instance}/statuses`, + url: `/api/pleroma/admin/instances/${instance}/statuses?page=${page}&page_size=${pageSize}`, method: 'get', headers: authHeaders(token) }) diff --git a/src/lang/en.js b/src/lang/en.js index f9c56069..396b2127 100644 --- a/src/lang/en.js +++ b/src/lang/en.js @@ -232,7 +232,8 @@ export default { }, statuses: { statuses: 'Statuses', - instanceFilter: 'Instance filter' + instanceFilter: 'Instance filter', + loadMore: 'Load more' }, userProfile: { tags: 'Tags', diff --git a/src/store/modules/status.js b/src/store/modules/status.js index a1a864b3..2a02bd70 100644 --- a/src/store/modules/status.js +++ b/src/store/modules/status.js @@ -9,6 +9,9 @@ const status = { SET_STATUSES: (state, statuses) => { state.fetchedStatuses = statuses }, + PUSH_STATUSES: (state, statuses) => { + state.fetchedStatuses = [...state.fetchedStatuses, ...statuses] + }, SET_LOADING: (state, status) => { state.loading = status } @@ -30,12 +33,19 @@ const status = { dispatch('FetchUserStatuses', { userId, godmode }) } }, - async FetchStatusesByInstance({ commit, getters }, instance) { + async FetchStatusesByInstance({ commit, getters }, { instance, page, pageSize }) { 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_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) } } } diff --git a/src/views/statuses/index.vue b/src/views/statuses/index.vue index adf56052..bcc98ac4 100644 --- a/src/views/statuses/index.vue +++ b/src/views/statuses/index.vue @@ -1,5 +1,5 @@ @@ -28,11 +31,12 @@ export default { data() { return { selectedInstance: '', - page: 1 + page: 1, + pageSize: 2 } }, computed: { - loading() { + loadingPeers() { return this.$store.state.peers.loading }, ...mapGetters([ @@ -47,7 +51,18 @@ export default { }, methods: { 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 { margin: 22px 15px 15px 0; } +.statuses-pagination { + padding: 15px 0; + text-align: center; +} h1 { margin: 22px 0 0 0; }