From 12f231b88693be2e946ee865ab75cf0771d1b690 Mon Sep 17 00:00:00 2001 From: mfcar Date: Sat, 4 Mar 2023 16:44:52 +0000 Subject: [PATCH] Add save action without closing the modal --- .../modals/podcast/tabs/EpisodeDetails.vue | 57 +++++++++++++------ 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/client/components/modals/podcast/tabs/EpisodeDetails.vue b/client/components/modals/podcast/tabs/EpisodeDetails.vue index cdc08f2f..1c486c2f 100644 --- a/client/components/modals/podcast/tabs/EpisodeDetails.vue +++ b/client/components/modals/podcast/tabs/EpisodeDetails.vue @@ -24,7 +24,12 @@
- {{ $strings.ButtonSubmit }} + + + + + + {{ $strings.ButtonSave }}

Episode URL from RSS feed

@@ -125,26 +130,44 @@ export default { } return updatePayload }, - submit() { - const payload = this.getUpdatePayload() - if (!Object.keys(payload).length) { - return this.$toast.info('No updates were made') + async saveAndClose() { + const wasUpdated = await this.submit() + if (wasUpdated !== null) this.$emit('close') + }, + async submit() { + if (this.isProcessing) { + return null } + const updatedDetails = this.getUpdatePayload() + if (!Object.keys(updatedDetails).length) { + this.$toast.info('No changes were made') + return false + } + return this.updateDetails(updatedDetails) + }, + async updateDetails(updatedDetails) { this.isProcessing = true - this.$axios - .$patch(`/api/podcasts/${this.libraryItem.id}/episode/${this.episodeId}`, payload) - .then(() => { - this.isProcessing = false + const updateResult = await this.$axios + .$patch(`/api/podcasts/${this.libraryItem.id}/episode/${this.episodeId}`, updatedDetails) + .catch((error) => { + const errorMsg = error.response && error.response.data ? error.response.data : 'Failed to update episode'; + console.error('Failed update episode', error) + this.isProcessing = false + this.$toast.error(errorMsg) + return false + }); + + this.isProcessing = false + if (updateResult) { + if (updateResult) { this.$toast.success('Podcast episode updated') - this.$emit('close') - }) - .catch((error) => { - var errorMsg = error.response && error.response.data ? error.response.data : 'Failed to update episode' - console.error('Failed update episode', error) - this.isProcessing = false - this.$toast.error(errorMsg) - }) + return true + } else { + this.$toast.info(this.$strings.MessageNoUpdatesWereNecessary) + } + } + return false } }, mounted() {}