Fix:Removing all sessions from last page of sessions table #1168

This commit is contained in:
advplyr 2022-11-16 16:28:46 -06:00
parent c3ec036009
commit 96a739e22d
2 changed files with 24 additions and 2 deletions

View File

@ -88,6 +88,7 @@ export default {
numPages: 0, numPages: 0,
total: 0, total: 0,
currentPage: 0, currentPage: 0,
itemsPerPage: 10,
userFilter: null, userFilter: null,
selectedUser: '', selectedUser: '',
processingGoToTimestamp: false processingGoToTimestamp: false
@ -112,6 +113,16 @@ export default {
}, },
methods: { methods: {
removedSession() { 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) this.loadSessions(this.currentPage)
}, },
async clickCurrentTime(session) { async clickCurrentTime(session) {
@ -208,7 +219,7 @@ export default {
}, },
async loadSessions(page) { async loadSessions(page) {
var userFilterQuery = this.selectedUser ? `&user=${this.selectedUser}` : '' 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) console.error('Failed to load listening sesions', err)
return null return null
}) })

View File

@ -86,6 +86,7 @@ export default {
numPages: 0, numPages: 0,
total: 0, total: 0,
currentPage: 0, currentPage: 0,
itemsPerPage: 10,
processingGoToTimestamp: false processingGoToTimestamp: false
} }
}, },
@ -99,6 +100,16 @@ export default {
}, },
methods: { methods: {
removedSession() { 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) this.loadSessions(this.currentPage)
}, },
async clickCurrentTime(session) { async clickCurrentTime(session) {
@ -191,7 +202,7 @@ export default {
return 'Unknown' return 'Unknown'
}, },
async loadSessions(page) { 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) console.error('Failed to load listening sesions', err)
return null return null
}) })