mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-19 00:18:56 +01:00
Merge pull request #3212 from mikiher/library-fetch
On item pages, fetch the item's library data to the store if it's not available
This commit is contained in:
commit
787c4e45a8
@ -56,8 +56,8 @@ export default {
|
||||
return redirect(`/library/${store.state.libraries.currentLibraryId}/authors`)
|
||||
}
|
||||
|
||||
if (query.library) {
|
||||
store.commit('libraries/setCurrentLibrary', query.library)
|
||||
if (store.state.libraries.currentLibraryId !== author.libraryId || !store.state.libraries.filterData) {
|
||||
await store.dispatch('libraries/fetch', author.libraryId)
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -168,6 +168,9 @@ export default {
|
||||
console.error('No item...', params.id)
|
||||
return redirect('/')
|
||||
}
|
||||
if (store.state.libraries.currentLibraryId !== item.libraryId || !store.state.libraries.filterData) {
|
||||
await store.dispatch('libraries/fetch', item.libraryId)
|
||||
}
|
||||
return {
|
||||
libraryItem: item,
|
||||
rssFeed: item.rssFeed || null,
|
||||
@ -791,10 +794,6 @@ export default {
|
||||
this.episodeDownloadsQueued = this.libraryItem.episodeDownloadsQueued || []
|
||||
this.episodesDownloading = this.libraryItem.episodesDownloading || []
|
||||
|
||||
// use this items library id as the current
|
||||
if (this.libraryId) {
|
||||
this.$store.commit('libraries/setCurrentLibrary', this.libraryId)
|
||||
}
|
||||
this.$eventBus.$on(`${this.libraryItem.id}_updated`, this.libraryItemUpdated)
|
||||
this.$root.socket.on('item_updated', this.libraryItemUpdated)
|
||||
this.$root.socket.on('rss_feed_open', this.rssFeedOpen)
|
||||
|
@ -54,11 +54,19 @@
|
||||
|
||||
<script>
|
||||
export default {
|
||||
async asyncData({ params, redirect }) {
|
||||
if (!params.library) {
|
||||
console.error('No library...', params.library)
|
||||
return redirect('/')
|
||||
async asyncData({ params, redirect, store }) {
|
||||
var libraryId = params.library
|
||||
var libraryData = await store.dispatch('libraries/fetch', libraryId)
|
||||
if (!libraryData) {
|
||||
return redirect('/oops?message=Library not found')
|
||||
}
|
||||
|
||||
// Redirect book libraries
|
||||
const library = libraryData.library
|
||||
if (library.mediaType === 'book') {
|
||||
return redirect(`/library/${libraryId}`)
|
||||
}
|
||||
|
||||
return {
|
||||
libraryId: params.library
|
||||
}
|
||||
@ -124,10 +132,6 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (this.libraryId) {
|
||||
this.$store.commit('libraries/setCurrentLibrary', this.libraryId)
|
||||
}
|
||||
|
||||
this.loadInitialDownloadQueue()
|
||||
},
|
||||
beforeDestroy() {
|
||||
|
@ -166,22 +166,6 @@ export const actions = {
|
||||
commit('set', [])
|
||||
})
|
||||
return true
|
||||
},
|
||||
loadLibraryFilterData({ state, commit, rootState }) {
|
||||
if (!rootState.user || !rootState.user.user) {
|
||||
console.error('libraries/loadLibraryFilterData - User not set')
|
||||
return false
|
||||
}
|
||||
|
||||
this.$axios
|
||||
.$get(`/api/libraries/${state.currentLibraryId}/filterdata`)
|
||||
.then((data) => {
|
||||
commit('setLibraryFilterData', data)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Failed', error)
|
||||
commit('setLibraryFilterData', null)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user