Fix edit modal registering/unregistering library item listeners #483

This commit is contained in:
advplyr 2022-04-22 17:42:49 -05:00
parent 1b79b3f42d
commit 663546dd77

View File

@ -181,15 +181,18 @@ export default {
if (this.currentBookshelfIndex - 1 < 0) return if (this.currentBookshelfIndex - 1 < 0) return
var prevBookId = this.bookshelfBookIds[this.currentBookshelfIndex - 1] var prevBookId = this.bookshelfBookIds[this.currentBookshelfIndex - 1]
this.processing = true this.processing = true
var prevBook = await this.$axios.$get(`/api/items/${prevBookId}`).catch((error) => { var prevBook = await this.$axios.$get(`/api/items/${prevBookId}?expanded=1`).catch((error) => {
var errorMsg = error.response && error.response.data ? error.response.data : 'Failed to fetch book' var errorMsg = error.response && error.response.data ? error.response.data : 'Failed to fetch book'
this.$toast.error(errorMsg) this.$toast.error(errorMsg)
return null return null
}) })
this.processing = false this.processing = false
if (prevBook) { if (prevBook) {
this.$store.commit('showEditModalOnTab', { libraryItem: prevBook, tab: this.selectedTab }) this.unregisterListeners()
this.$nextTick(this.init) this.libraryItem = prevBook
this.selectedTab = 'details'
this.$store.commit('setSelectedLibraryItem', prevBook)
this.$nextTick(this.registerListeners)
} else { } else {
console.error('Book not found', prevBookId) console.error('Book not found', prevBookId)
} }
@ -198,15 +201,18 @@ export default {
if (this.currentBookshelfIndex >= this.bookshelfBookIds.length - 1) return if (this.currentBookshelfIndex >= this.bookshelfBookIds.length - 1) return
this.processing = true this.processing = true
var nextBookId = this.bookshelfBookIds[this.currentBookshelfIndex + 1] var nextBookId = this.bookshelfBookIds[this.currentBookshelfIndex + 1]
var nextBook = await this.$axios.$get(`/api/items/${nextBookId}`).catch((error) => { var nextBook = await this.$axios.$get(`/api/items/${nextBookId}?expanded=1`).catch((error) => {
var errorMsg = error.response && error.response.data ? error.response.data : 'Failed to fetch book' var errorMsg = error.response && error.response.data ? error.response.data : 'Failed to fetch book'
this.$toast.error(errorMsg) this.$toast.error(errorMsg)
return null return null
}) })
this.processing = false this.processing = false
if (nextBook) { if (nextBook) {
this.$store.commit('showEditModalOnTab', { libraryItem: nextBook, tab: this.selectedTab }) this.unregisterListeners()
this.$nextTick(this.init) this.libraryItem = nextBook
this.selectedTab = 'details'
this.$store.commit('setSelectedLibraryItem', nextBook)
this.$nextTick(this.registerListeners)
} else { } else {
console.error('Book not found', nextBookId) console.error('Book not found', nextBookId)
} }