diff --git a/pages/collection/_id.vue b/pages/collection/_id.vue index 9f371c66..c4c5b188 100644 --- a/pages/collection/_id.vue +++ b/pages/collection/_id.vue @@ -135,8 +135,20 @@ export default { this.$eventBus.$emit('play-item', { libraryItemId: nextBookNotRead.id }) } } + }, + libraryChanged(libraryId) { + // A collection belongs to a single library, so leave this page when a different library is + // selected rather than showing a collection that is not in the current library + if (!libraryId || libraryId !== this.collection.libraryId) { + this.$router.replace('/bookshelf/collections') + } } }, - mounted() {} + mounted() { + this.$eventBus.$on('library-changed', this.libraryChanged) + }, + beforeDestroy() { + this.$eventBus.$off('library-changed', this.libraryChanged) + } } diff --git a/pages/playlist/_id.vue b/pages/playlist/_id.vue index 6f84cc8b..077b9ebc 100644 --- a/pages/playlist/_id.vue +++ b/pages/playlist/_id.vue @@ -162,13 +162,20 @@ export default { if (this.playlist.id === playlist.id) { this.$router.replace('/bookshelf/playlists') } + }, + libraryChanged() { + // Playlist contents are shown in the context of the selected library, so leave this page + // when the library changes rather than showing stale items + this.$router.replace('/bookshelf/playlists') } }, mounted() { + this.$eventBus.$on('library-changed', this.libraryChanged) this.$socket.$on('playlist_updated', this.playlistUpdated) this.$socket.$on('playlist_removed', this.playlistRemoved) }, beforeDestroy() { + this.$eventBus.$off('library-changed', this.libraryChanged) this.$socket.$off('playlist_updated', this.playlistUpdated) this.$socket.$off('playlist_removed', this.playlistRemoved) }