From 96a739e22d05986fc02ec084a919f77c9de10f60 Mon Sep 17 00:00:00 2001 From: advplyr Date: Wed, 16 Nov 2022 16:28:46 -0600 Subject: [PATCH] Fix:Removing all sessions from last page of sessions table #1168 --- client/pages/config/sessions.vue | 13 ++++++++++++- client/pages/config/users/_id/sessions.vue | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/client/pages/config/sessions.vue b/client/pages/config/sessions.vue index 0ca72da7..adb34662 100644 --- a/client/pages/config/sessions.vue +++ b/client/pages/config/sessions.vue @@ -88,6 +88,7 @@ export default { numPages: 0, total: 0, currentPage: 0, + itemsPerPage: 10, userFilter: null, selectedUser: '', processingGoToTimestamp: false @@ -112,6 +113,16 @@ export default { }, methods: { removedSession() { + // If on last page and this was the last session then load prev page + if (this.currentPage == this.numPages - 1) { + const newTotal = this.total - 1 + const newNumPages = Math.ceil(newTotal / this.itemsPerPage) + if (newNumPages < this.numPages) { + this.prevPage() + return + } + } + this.loadSessions(this.currentPage) }, async clickCurrentTime(session) { @@ -208,7 +219,7 @@ export default { }, async loadSessions(page) { var userFilterQuery = this.selectedUser ? `&user=${this.selectedUser}` : '' - const data = await this.$axios.$get(`/api/sessions?page=${page}&itemsPerPage=10${userFilterQuery}`).catch((err) => { + const data = await this.$axios.$get(`/api/sessions?page=${page}&itemsPerPage=${this.itemsPerPage}${userFilterQuery}`).catch((err) => { console.error('Failed to load listening sesions', err) return null }) diff --git a/client/pages/config/users/_id/sessions.vue b/client/pages/config/users/_id/sessions.vue index 2d2dd4e9..7377a91d 100644 --- a/client/pages/config/users/_id/sessions.vue +++ b/client/pages/config/users/_id/sessions.vue @@ -86,6 +86,7 @@ export default { numPages: 0, total: 0, currentPage: 0, + itemsPerPage: 10, processingGoToTimestamp: false } }, @@ -99,6 +100,16 @@ export default { }, methods: { removedSession() { + // If on last page and this was the last session then load prev page + if (this.currentPage == this.numPages - 1) { + const newTotal = this.total - 1 + const newNumPages = Math.ceil(newTotal / this.itemsPerPage) + if (newNumPages < this.numPages) { + this.prevPage() + return + } + } + this.loadSessions(this.currentPage) }, async clickCurrentTime(session) { @@ -191,7 +202,7 @@ export default { return 'Unknown' }, async loadSessions(page) { - const data = await this.$axios.$get(`/api/users/${this.user.id}/listening-sessions?page=${page}&itemsPerPage=10`).catch((err) => { + const data = await this.$axios.$get(`/api/users/${this.user.id}/listening-sessions?page=${page}&itemsPerPage=${this.itemsPerPage}`).catch((err) => { console.error('Failed to load listening sesions', err) return null })