Skip to content

Commit

Permalink
Merge pull request #3212 from mikiher/library-fetch
Browse files Browse the repository at this point in the history
On item pages, fetch the item's library data to the store if it's not available
  • Loading branch information
advplyr authored Jul 30, 2024
2 parents ed70f3a + 34cb7a4 commit 787c4e4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 30 deletions.
4 changes: 2 additions & 2 deletions client/pages/author/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions client/pages/item/_id/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 12 additions & 8 deletions client/pages/library/_library/podcast/download-queue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -124,10 +132,6 @@ export default {
}
},
mounted() {
if (this.libraryId) {
this.$store.commit('libraries/setCurrentLibrary', this.libraryId)
}
this.loadInitialDownloadQueue()
},
beforeDestroy() {
Expand Down
16 changes: 0 additions & 16 deletions client/store/libraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}

Expand Down

0 comments on commit 787c4e4

Please sign in to comment.