From 8792f02932e6e47819a52526e37de4c413a4fc1a Mon Sep 17 00:00:00 2001 From: Grzegorz Leoniec Date: Tue, 5 Mar 2019 17:35:41 +0100 Subject: [PATCH] Improved follow button optimistic behavior --- components/Author.vue | 1 + components/FollowButton.vue | 9 +++------ pages/profile/_slug.vue | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/components/Author.vue b/components/Author.vue index f12e53d3e..773037fac 100644 --- a/components/Author.vue +++ b/components/Author.vue @@ -109,6 +109,7 @@ :follow-id="author.id" :is-followed="author.followedByCurrentUser" @optimistic="follow => author.followedByCurrentUser = follow" + @update="follow => author.followedByCurrentUser = follow" /> diff --git a/components/FollowButton.vue b/components/FollowButton.vue index 7cce2e65a..676aa1a83 100644 --- a/components/FollowButton.vue +++ b/components/FollowButton.vue @@ -79,14 +79,11 @@ export default { } }) .then(res => { - if (res && res.data) { - this.$emit('update', follow) - } else { - this.$emit('optimistic', this.isFollowed) - } + this.$emit('update', follow ? res.data.follow : follow) + this.$emit('optimistic', follow ? res.data.follow : follow) }) .catch(() => { - this.$emit('optimistic', this.isFollowed) + this.$emit('optimistic', !follow) }) } } diff --git a/pages/profile/_slug.vue b/pages/profile/_slug.vue index 5880921c0..f83e25e1f 100644 --- a/pages/profile/_slug.vue +++ b/pages/profile/_slug.vue @@ -88,7 +88,7 @@ :follow-id="user.id" :is-followed="user.followedByCurrentUser" @optimistic="follow => user.followedByCurrentUser = follow" - @update="follow => fetchUser()" + @update="follow => user.followedByCurrentUser = follow && fetchUser()" />