diff --git a/webapp/components/FollowButton.vue b/webapp/components/FollowButton.vue index 7372b8a78..cc4662c85 100644 --- a/webapp/components/FollowButton.vue +++ b/webapp/components/FollowButton.vue @@ -59,16 +59,15 @@ export default { this.hovered = true } }, - toggle() { + async toggle() { const follow = !this.isFollowed const mutation = follow ? 'follow' : 'unfollow' this.hovered = false - this.$emit('optimistic', follow) - this.$apollo - .mutate({ + try { + await this.$apollo.mutate({ mutation: gql` mutation($id: ID!) { ${mutation}(id: $id, type: User) @@ -78,13 +77,11 @@ export default { id: this.followId, }, }) - .then(res => { - // this.$emit('optimistic', follow ? res.data.follow : follow) - this.$emit('update', follow) - }) - .catch(() => { - this.$emit('optimistic', !follow) - }) + + this.$emit('update', follow) + } catch { + this.$emit('optimistic', !follow) + } }, }, } diff --git a/webapp/components/User/User.vue b/webapp/components/User/User.vue index 080a4fcab..7c97c5755 100644 --- a/webapp/components/User/User.vue +++ b/webapp/components/User/User.vue @@ -71,8 +71,8 @@ @@ -131,6 +131,16 @@ export default { return name || this.$t('profile.userAnonym') }, }, + methods: { + optimisticFollow(follow) { + const inc = follow ? 1 : -1 + this.user.followedByCurrentUser = follow + this.user.followedByCount += inc + }, + updateFollow(follow) { + this.user.followedByCurrentUser = follow + }, + }, }