diff --git a/components/modals/LibrariesModal.vue b/components/modals/LibrariesModal.vue index c7fc936e..e5b50905 100644 --- a/components/modals/LibrariesModal.vue +++ b/components/modals/LibrariesModal.vue @@ -50,8 +50,9 @@ export default { methods: { async clickedOption(lib) { this.show = false + if (lib.id === this.currentLibraryId) return await this.$store.dispatch('libraries/fetch', lib.id) - this.$eventBus.$emit('library-changed') + this.$eventBus.$emit('library-changed', lib.id) this.$localStore.setLastLibraryId(lib.id) } }, diff --git a/pages/item/_id.vue b/pages/item/_id.vue index 53e886f6..3a7a4b94 100644 --- a/pages/item/_id.vue +++ b/pages/item/_id.vue @@ -583,13 +583,20 @@ export default { this.$toast.error(`Failed to mark as ${updatePayload.isFinished ? 'Finished' : 'Not Finished'}`) }) } + }, + libraryChanged(libraryId) { + if (this.libraryItem.libraryId !== libraryId) { + this.$router.replace('/bookshelf') + } } }, mounted() { + this.$eventBus.$on('library-changed', this.libraryChanged) this.$eventBus.$on('new-local-library-item', this.newLocalLibraryItem) this.$socket.on('item_updated', this.itemUpdated) }, beforeDestroy() { + this.$eventBus.$off('library-changed', this.libraryChanged) this.$eventBus.$off('new-local-library-item', this.newLocalLibraryItem) this.$socket.off('item_updated', this.itemUpdated) }