Make follow button update instant

This commit is contained in:
Grzegorz Leoniec 2019-03-05 17:26:20 +01:00
parent d30649164a
commit d9b633c5ae
No known key found for this signature in database
GPG Key ID: 3AA43686D4EB1377
4 changed files with 12 additions and 7 deletions

View File

@ -108,7 +108,7 @@
<hc-follow-button
:follow-id="author.id"
:is-followed="author.followedByCurrentUser"
@update="following => author.followedByCurrentUser = following"
@optimistic="follow => author.followedByCurrentUser = follow"
/>
</ds-flex-item>
<ds-flex-item :width="{base: 1}">

View File

@ -64,6 +64,9 @@ export default {
const mutation = follow ? 'follow' : 'unfollow'
this.hovered = false
this.$emit('optimistic', follow)
this.$apollo
.mutate({
mutation: gql`
@ -78,8 +81,13 @@ export default {
.then(res => {
if (res && res.data) {
this.$emit('update', follow)
} else {
this.$emit('optimistic', this.isFollowed)
}
})
.catch(() => {
this.$emit('optimistic', this.isFollowed)
})
}
}
}

View File

@ -79,7 +79,7 @@ export default {
})
.then(res => {
if (res && res.data) {
this.$emit('update')
this.$emit('update', shout)
}
})
.catch(() => {

View File

@ -87,7 +87,8 @@
v-if="!myProfile"
:follow-id="user.id"
:is-followed="user.followedByCurrentUser"
@update="voted = true && fetchUser()"
@optimistic="follow => user.followedByCurrentUser = follow"
@update="follow => fetchUser()"
/>
</ds-space>
<template v-if="user.about">
@ -336,10 +337,6 @@ export default {
},
followedByCount() {
let count = Number(this.user.followedByCount) || 0
if (this.voted) {
// NOTE: this is used for presentation
count += 1
}
return count
},
user() {