Update providers users to fetch providers on demand

This commit is contained in:
mikiher 2025-10-19 18:57:27 +03:00
parent 166e0442a0
commit 538a5065a4
7 changed files with 52 additions and 20 deletions

View File

@ -96,6 +96,9 @@ export default {
}, },
methods: { methods: {
init() { init() {
// Fetch providers when modal is shown
this.$store.dispatch('scanners/fetchProviders')
// If we don't have a set provider (first open of dialog) or we've switched library, set // If we don't have a set provider (first open of dialog) or we've switched library, set
// the selected provider to the current library default provider // the selected provider to the current library default provider
if (!this.options.provider || this.lastUsedLibrary != this.currentLibraryId) { if (!this.options.provider || this.lastUsedLibrary != this.currentLibraryId) {
@ -127,8 +130,7 @@ export default {
this.show = false this.show = false
}) })
} }
}, }
mounted() {}
} }
</script> </script>

View File

@ -438,6 +438,8 @@ export default {
mounted() { mounted() {
// Setup socket listeners when component is mounted // Setup socket listeners when component is mounted
this.addSocketListeners() this.addSocketListeners()
// Fetch providers if not already loaded
this.$store.dispatch('scanners/fetchProviders')
}, },
beforeDestroy() { beforeDestroy() {
// Cancel any ongoing search when component is destroyed // Cancel any ongoing search when component is destroyed

View File

@ -2,7 +2,7 @@
<div id="match-wrapper" class="w-full h-full overflow-hidden px-2 md:px-4 py-4 md:py-6 relative"> <div id="match-wrapper" class="w-full h-full overflow-hidden px-2 md:px-4 py-4 md:py-6 relative">
<form @submit.prevent="submitSearch"> <form @submit.prevent="submitSearch">
<div class="flex flex-wrap md:flex-nowrap items-center justify-start -mx-1"> <div class="flex flex-wrap md:flex-nowrap items-center justify-start -mx-1">
<div class="w-36 px-1"> <div v-if="providersLoaded" class="w-36 px-1">
<ui-dropdown v-model="provider" :items="providers" :label="$strings.LabelProvider" small /> <ui-dropdown v-model="provider" :items="providers" :label="$strings.LabelProvider" small />
</div> </div>
<div class="grow md:w-72 px-1"> <div class="grow md:w-72 px-1">
@ -253,6 +253,7 @@ export default {
hasSearched: false, hasSearched: false,
selectedMatch: null, selectedMatch: null,
selectedMatchOrig: null, selectedMatchOrig: null,
waitingForProviders: false,
selectedMatchUsage: { selectedMatchUsage: {
title: true, title: true,
subtitle: true, subtitle: true,
@ -285,9 +286,19 @@ export default {
handler(newVal) { handler(newVal) {
if (newVal) this.init() if (newVal) this.init()
} }
},
providersLoaded(isLoaded) {
// Complete initialization once providers are loaded
if (isLoaded && this.waitingForProviders) {
this.waitingForProviders = false
this.initProviderAndSearch()
}
} }
}, },
computed: { computed: {
providersLoaded() {
return this.$store.getters['scanners/areProvidersLoaded']
},
isProcessing: { isProcessing: {
get() { get() {
return this.processing return this.processing
@ -478,6 +489,24 @@ export default {
this.checkboxToggled() this.checkboxToggled()
}, },
initProviderAndSearch() {
// Set provider based on media type
if (this.isPodcast) {
this.provider = 'itunes'
} else {
this.provider = this.getDefaultBookProvider()
}
// Prefer using ASIN if set and using audible provider
if (this.provider.startsWith('audible') && this.libraryItem.media.metadata.asin) {
this.searchTitle = this.libraryItem.media.metadata.asin
this.searchAuthor = ''
}
if (this.searchTitle) {
this.submitSearch()
}
},
init() { init() {
this.clearSelectedMatch() this.clearSelectedMatch()
this.initSelectedMatchUsage() this.initSelectedMatchUsage()
@ -495,19 +524,13 @@ export default {
} }
this.searchTitle = this.libraryItem.media.metadata.title this.searchTitle = this.libraryItem.media.metadata.title
this.searchAuthor = this.libraryItem.media.metadata.authorName || '' this.searchAuthor = this.libraryItem.media.metadata.authorName || ''
if (this.isPodcast) this.provider = 'itunes'
else {
this.provider = this.getDefaultBookProvider()
}
// Prefer using ASIN if set and using audible provider // Wait for providers to be loaded before setting provider and searching
if (this.provider.startsWith('audible') && this.libraryItem.media.metadata.asin) { if (this.providersLoaded || this.isPodcast) {
this.searchTitle = this.libraryItem.media.metadata.asin this.waitingForProviders = false
this.searchAuthor = '' this.initProviderAndSearch()
} } else {
this.waitingForProviders = true
if (this.searchTitle) {
this.submitSearch()
} }
}, },
selectMatch(match) { selectMatch(match) {
@ -637,6 +660,10 @@ export default {
this.selectedMatch = null this.selectedMatch = null
this.selectedMatchOrig = null this.selectedMatchOrig = null
} }
},
mounted() {
// Fetch providers if not already loaded
this.$store.dispatch('scanners/fetchProviders')
} }
} }
</script> </script>

View File

@ -156,6 +156,8 @@ export default {
}, },
mounted() { mounted() {
this.init() this.init()
// Fetch providers if not already loaded
this.$store.dispatch('scanners/fetchProviders')
} }
} }
</script> </script>

View File

@ -104,7 +104,6 @@ export default {
}, },
data() { data() {
return { return {
provider: null,
useSquareBookCovers: false, useSquareBookCovers: false,
enableWatcher: false, enableWatcher: false,
skipMatchingMediaWithAsin: false, skipMatchingMediaWithAsin: false,
@ -134,10 +133,6 @@ export default {
isPodcastLibrary() { isPodcastLibrary() {
return this.mediaType === 'podcast' return this.mediaType === 'podcast'
}, },
providers() {
if (this.mediaType === 'podcast') return this.$store.state.scanners.podcastProviders
return this.$store.state.scanners.bookProviders
},
maskAsFinishedWhenItems() { maskAsFinishedWhenItems() {
return [ return [
{ {

View File

@ -417,6 +417,8 @@ export default {
}, },
mounted() { mounted() {
this.initServerSettings() this.initServerSettings()
// Fetch providers if not already loaded (for cover provider dropdown)
this.$store.dispatch('scanners/fetchProviders')
} }
} }
</script> </script>

View File

@ -394,6 +394,8 @@ export default {
this.setMetadataProvider() this.setMetadataProvider()
this.setDefaultFolder() this.setDefaultFolder()
// Fetch providers if not already loaded
this.$store.dispatch('scanners/fetchProviders')
window.addEventListener('dragenter', this.dragenter) window.addEventListener('dragenter', this.dragenter)
window.addEventListener('dragleave', this.dragleave) window.addEventListener('dragleave', this.dragleave)
window.addEventListener('dragover', this.dragover) window.addEventListener('dragover', this.dragover)