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,
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
})

View File

@ -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
})