Revert to using async/await, follow @appinteractive PR suggestions

This commit is contained in:
Matt Rider 2019-08-27 09:55:05 +02:00
parent ed76482daa
commit 470da18381
2 changed files with 14 additions and 16 deletions

View File

@ -141,13 +141,13 @@ export default {
this.openEditCommentMenu = showMenu
this.setEditPending(showMenu)
},
deleteCommentCallback() {
this.$apollo
.mutate({
async deleteCommentCallback() {
try {
await this.$apollo.mutate({
mutation: CommentMutations(this.$i18n).DeleteComment,
variables: { id: this.comment.id },
update: store => {
const data = store.readQuery({
update: async store => {
const data = await store.readQuery({
query: PostQuery(this.$i18n),
variables: { id: this.post.id },
})
@ -158,16 +158,14 @@ export default {
if (index !== -1) {
data.Post[0].comments.splice(index, 1)
}
store.writeQuery({ query: PostQuery(this.$i18n), data })
await store.writeQuery({ query: PostQuery(this.$i18n), data })
},
})
.then(res => {
this.$toast.success(this.$t(`delete.comment.success`))
this.$emit('deleteComment')
})
.catch(err => {
this.$toast.error(err.message)
})
this.$toast.success(this.$t(`delete.comment.success`))
this.$emit('deleteComment')
} catch (err) {
this.$toast.error(err.message)
}
},
},
}

View File

@ -80,13 +80,13 @@ export default {
postId: this.post.id,
content: this.form.content,
},
update: (store, { data: { CreateComment } }) => {
const data = store.readQuery({
update: async (store, { data: { CreateComment } }) => {
const data = await store.readQuery({
query: PostQuery(this.$i18n),
variables: { id: this.post.id },
})
data.Post[0].comments.push(CreateComment)
store.writeQuery({ query: PostQuery(this.$i18n), data })
await store.writeQuery({ query: PostQuery(this.$i18n), data })
},
})
.then(res => {