Refactor ReportModal

@Tirokk and I had a hard time to reason about the then/catch block if
$toast is undefined.
This commit is contained in:
Robert Schäfer 2019-03-08 17:16:17 +01:00
parent 193cff45e2
commit c0d545bae0

View File

@ -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
}
}
}
}