From 11e3cf4f191570d61a4ef17b65fcdd66a1c322ca Mon Sep 17 00:00:00 2001 From: Nick Thomson Date: Sat, 24 Sep 2022 18:23:33 +0100 Subject: [PATCH] Initialise the selected provider to the default for the library when the batch quick match is first opened or if the user has switched libraries. --- .../modals/BatchQuickMatchModel.vue | 72 ++++++++++++------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/client/components/modals/BatchQuickMatchModel.vue b/client/components/modals/BatchQuickMatchModel.vue index fd30d9e9..9c4115cd 100644 --- a/client/components/modals/BatchQuickMatchModel.vue +++ b/client/components/modals/BatchQuickMatchModel.vue @@ -54,8 +54,10 @@ export default { data() { return { processing: false, + isScrollable: false, + lastUsedLibrary: undefined, options: { - provider: 'google', + provider: undefined, overrideDetails: true, overrideCover: true, overrideDefaults: true @@ -66,6 +68,13 @@ export default { } } }, + watch: { + show: { + handler(newVal) { + this.init() + } + } + }, computed: { show: { get() { @@ -90,34 +99,45 @@ export default { providers() { if (this.isPodcast) return this.$store.state.scanners.podcastProviders return this.$store.state.scanners.providers - } + }, + libraryProvider() { + return this.$store.getters['libraries/getLibraryProvider'](this.currentLibraryId) || 'google' + }, }, methods: { - doBatchQuickMatch() { - if (!this.selectedBookIds.length) return - if (this.processing) return - - this.processing = true - this.$store.commit('setProcessingBatch', true) - this.$axios - .$post(`/api/items/batch/quickmatch`, { - options: this.options, - libraryItemIds: this.selectedBookIds - }) - .then(() => { - this.$toast.success('Batch quick match success!') - this.processing = false - this.$store.commit('setProcessingBatch', false) - this.show = false - }) - .catch((error) => { - this.$toast.error('Batch quick match failed') - console.error('Failed to batch quick match', error) - this.processing = false - this.$store.commit('setProcessingBatch', false) - this.show = false - }) + init() { + // 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 + if (!this.options.provider || (this.options.lastUsedLibrary != this.currentLibraryId)) { + this.options.lastUsedLibrary = this.currentLibraryId + this.options.provider = this.libraryProvider; } + }, + doBatchQuickMatch() { + if (!this.selectedBookIds.length) return + if (this.processing) return + + this.processing = true + this.$store.commit('setProcessingBatch', true) + this.$axios + .$post(`/api/items/batch/quickmatch`, { + options: this.options, + libraryItemIds: this.selectedBookIds + }) + .then(() => { + this.$toast.success('Batch quick match success!') + this.processing = false + this.$store.commit('setProcessingBatch', false) + this.show = false + }) + .catch((error) => { + this.$toast.error('Batch quick match failed') + console.error('Failed to batch quick match', error) + this.processing = false + this.$store.commit('setProcessingBatch', false) + this.show = false + }) + } }, mounted() {} }