From 14ff9097c79738f1f0b7e94147314c1eb3f62663 Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 25 Aug 2022 17:58:29 -0500 Subject: [PATCH] Update:Changing library while on item page redirects to home --- components/modals/LibrariesModal.vue | 3 ++- pages/item/_id.vue | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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) }