From c0d545bae0b5693030a609d8cf2b79ba9c41b92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Fri, 8 Mar 2019 17:16:17 +0100 Subject: [PATCH] Refactor ReportModal @Tirokk and I had a hard time to reason about the then/catch block if $toast is undefined. --- components/ReportModal.vue | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/components/ReportModal.vue b/components/ReportModal.vue index 6e5af56f5..e331e6e48 100644 --- a/components/ReportModal.vue +++ b/components/ReportModal.vue @@ -94,11 +94,11 @@ export default { close() { this.$store.commit('modal/SET_OPEN', {}) }, - report() { + async report() { this.loading = true this.disabled = true - this.$apollo - .mutate({ + try { + await this.$apollo.mutate({ mutation: gql` mutation($id: ID!, $description: String) { report(id: $id, description: $description) { @@ -111,18 +111,15 @@ export default { description: '-' } }) - .then(() => { - this.success = true - this.$toast.success('Thanks for reporting!') - setTimeout(this.close, 1500) - }) - .catch(err => { - this.$toast.error(err.message) - this.disabled = false - }) - .finally(() => { - this.loading = false - }) + this.success = true + this.$toast.success('Thanks for reporting!') + setTimeout(this.close, 1500) + } catch (err) { + this.$toast.error(err.message) + this.disabled = false + } finally { + this.loading = false + } } } }