diff --git a/pages/bookshelf/authors.vue b/pages/bookshelf/authors.vue index bb4a628d..8b8202c3 100644 --- a/pages/bookshelf/authors.vue +++ b/pages/bookshelf/authors.vue @@ -15,7 +15,8 @@ export default { data() { return { loading: true, - authors: [] + authors: [], + loadedLibraryId: null } }, computed: { @@ -25,6 +26,7 @@ export default { }, methods: { async init() { + this.loadedLibraryId = this.currentLibraryId this.authors = await this.$axios .$get(`/api/libraries/${this.currentLibraryId}/authors`) .then((response) => response.authors) @@ -53,6 +55,15 @@ export default { authorRemoved(author) { this.authors = this.authors.filter((au) => au.id !== author.id) this.$eventBus.$emit('bookshelf-total-entities', this.authors.length) + }, + libraryChanged(libraryId) { + if (libraryId !== this.loadedLibraryId) { + if (this.$store.getters['libraries/getCurrentLibraryMediaType'] === 'book') { + this.init() + } else { + this.$router.replace('/bookshelf') + } + } } }, mounted() { @@ -60,11 +71,13 @@ export default { this.$socket.$on('author_added', this.authorAdded) this.$socket.$on('author_updated', this.authorUpdated) this.$socket.$on('author_removed', this.authorRemoved) + this.$eventBus.$on('library-changed', this.libraryChanged) }, beforeDestroy() { this.$socket.$off('author_added', this.authorAdded) this.$socket.$off('author_updated', this.authorUpdated) this.$socket.$off('author_removed', this.authorRemoved) + this.$eventBus.$off('library-changed', this.libraryChanged) } } \ No newline at end of file diff --git a/pages/bookshelf/latest.vue b/pages/bookshelf/latest.vue index e9871040..7b783dd2 100644 --- a/pages/bookshelf/latest.vue +++ b/pages/bookshelf/latest.vue @@ -17,7 +17,8 @@ export default { totalEpisodes: 0, currentPage: 0, localEpisodeMap: {}, - isLocal: false + isLocal: false, + loadedLibraryId: null } }, watch: {}, @@ -39,6 +40,7 @@ export default { this.$store.commit('globals/setShowPlaylistsAddCreateModal', true) }, async loadRecentEpisodes(page = 0) { + this.loadedLibraryId = this.currentLibraryId this.processing = true const episodePayload = await this.$axios.$get(`/api/libraries/${this.currentLibraryId}/recent-episodes?limit=25&page=${page}`).catch((error) => { console.error('Failed to get recent episodes', error) @@ -50,10 +52,23 @@ export default { this.recentEpisodes = episodePayload.episodes || [] this.totalEpisodes = episodePayload.total this.currentPage = page + }, + libraryChanged(libraryId) { + if (libraryId !== this.loadedLibraryId) { + if (this.$store.getters['libraries/getCurrentLibraryMediaType'] === 'podcast') { + this.loadRecentEpisodes() + } else { + this.$router.replace('/bookshelf') + } + } } }, mounted() { this.loadRecentEpisodes() + this.$eventBus.$on('library-changed', this.libraryChanged) + }, + beforeDestroy() { + this.$eventBus.$off('library-changed', this.libraryChanged) } } \ No newline at end of file