From bcd8401b3198544b502ba867c464ebd24c1196b6 Mon Sep 17 00:00:00 2001 From: Lukas Hirt Date: Wed, 7 Jul 2021 13:14:29 +0200 Subject: [PATCH 1/6] feat: add page size --- .../src/components/FilesList/Pagination.vue | 58 +++++++++++++++++++ .../src/mixins/filesListPagination.js | 39 ++++++++++++- packages/web-app-files/src/store/getters.js | 12 +++- packages/web-app-files/src/store/mutations.js | 6 ++ packages/web-app-files/src/store/state.js | 2 +- .../web-app-files/src/views/Favorites.vue | 31 +++------- .../src/views/LocationPicker.vue | 23 +++----- packages/web-app-files/src/views/Personal.vue | 24 +++----- .../web-app-files/src/views/PublicFiles.vue | 28 ++++----- .../web-app-files/src/views/SharedViaLink.vue | 37 +++--------- .../web-app-files/src/views/SharedWithMe.vue | 30 +++------- .../src/views/SharedWithOthers.vue | 36 +++--------- packages/web-app-files/src/views/Trashbin.vue | 25 ++------ 13 files changed, 177 insertions(+), 174 deletions(-) create mode 100644 packages/web-app-files/src/components/FilesList/Pagination.vue diff --git a/packages/web-app-files/src/components/FilesList/Pagination.vue b/packages/web-app-files/src/components/FilesList/Pagination.vue new file mode 100644 index 00000000000..20570fe7f81 --- /dev/null +++ b/packages/web-app-files/src/components/FilesList/Pagination.vue @@ -0,0 +1,58 @@ + + + + + diff --git a/packages/web-app-files/src/mixins/filesListPagination.js b/packages/web-app-files/src/mixins/filesListPagination.js index 97df4ffcd56..dc48d8d98b2 100644 --- a/packages/web-app-files/src/mixins/filesListPagination.js +++ b/packages/web-app-files/src/mixins/filesListPagination.js @@ -1,19 +1,54 @@ -import { mapMutations } from 'vuex' +import { mapMutations, mapState } from 'vuex' export default { computed: { + ...mapState('Files', ['filesPageLimit']), + $_filesListPagination_targetRoute() { return { name: this.$route.name, query: this.$route.query, params: this.$route.params } + }, + + $_filesListPagination_pageItemsLimit: { + get() { + return this.filesPageLimit + }, + + set(value) { + this.SET_FILES_PAGE_LIMIT(value) + this.$_filesListPagination_updateQuery(value) + } + } + }, + + watch: { + $route: { + handler(route) { + if (Object.prototype.hasOwnProperty.call(route.query, 'items-limit')) { + this.SET_FILES_PAGE_LIMIT(route.query['items-limit']) + + return + } + + this.$_filesListPagination_updateQuery() + }, + immediate: true } }, methods: { - ...mapMutations('Files', ['UPDATE_CURRENT_PAGE']), + ...mapMutations('Files', ['UPDATE_CURRENT_PAGE', 'SET_FILES_PAGE_LIMIT']), $_filesListPagination_updateCurrentPage() { const page = this.$route.params.page || 1 this.UPDATE_CURRENT_PAGE(page) + }, + + $_filesListPagination_updateQuery(limit = this.$_filesListPagination_pageItemsLimit) { + const query = { ...this.$route.query, 'items-limit': limit } + + this.SET_FILES_PAGE_LIMIT(limit) + this.$router.replace({ query }).catch(() => {}) } } } diff --git a/packages/web-app-files/src/store/getters.js b/packages/web-app-files/src/store/getters.js index dc57ccbf2f5..daa3d677638 100644 --- a/packages/web-app-files/src/store/getters.js +++ b/packages/web-app-files/src/store/getters.js @@ -28,13 +28,19 @@ export default { }, pages: (state, getters) => Math.ceil(getters.filesAll.length / state.filesPageLimit), activeFiles: (state, getters) => { - let files = getters.filesAll - const firstElementIndex = (state.currentPage - 1) * state.filesPageLimit + let files = [].concat(getters.filesAll) if (!state.areHiddenFilesShown) { files = files.filter(file => !file.name.startsWith('.')) } - return [].concat(files).splice(firstElementIndex, state.filesPageLimit) + + if (state.filesPageLimit > 0) { + const firstElementIndex = (state.currentPage - 1) * state.filesPageLimit + + return files.splice(firstElementIndex, state.filesPageLimit) + } + + return files }, activeFilesSize: (state, getters) => { return $_fileSizes(getters.activeFiles) diff --git a/packages/web-app-files/src/store/mutations.js b/packages/web-app-files/src/store/mutations.js index 0afeb4c671e..6f91172c78f 100644 --- a/packages/web-app-files/src/store/mutations.js +++ b/packages/web-app-files/src/store/mutations.js @@ -373,6 +373,12 @@ export default { state.areHiddenFilesShown = value window.localStorage.setItem('oc_hiddenFilesShown', value) + }, + + SET_FILES_PAGE_LIMIT(state, limit) { + state.filesPageLimit = limit + + window.localStorage.setItem('oc_filesPageLimit', limit) } } diff --git a/packages/web-app-files/src/store/state.js b/packages/web-app-files/src/store/state.js index 6700e0c7296..7701e26397f 100644 --- a/packages/web-app-files/src/store/state.js +++ b/packages/web-app-files/src/store/state.js @@ -72,7 +72,7 @@ export default { * Pagination */ currentPage: 1, - filesPageLimit: 100, // TODO: Replace with dynamic value from settings once available + filesPageLimit: 100, /** * View settings diff --git a/packages/web-app-files/src/views/Favorites.vue b/packages/web-app-files/src/views/Favorites.vue index 29428f20945..f74fed536e6 100644 --- a/packages/web-app-files/src/views/Favorites.vue +++ b/packages/web-app-files/src/views/Favorites.vue @@ -27,14 +27,7 @@