From 76c4e4cd8f261c0a96513a710b05f1a6ea9efafa Mon Sep 17 00:00:00 2001 From: Grzegorz Leoniec Date: Sun, 3 Mar 2019 19:30:54 +0100 Subject: [PATCH 01/14] Show status of follows and shouts for currently logged in user --- components/Author.vue | 1 + components/FollowButton.vue | 5 +++-- components/ShoutButton.vue | 5 +++-- graphql/UserProfileQuery.js | 3 +++ pages/index.vue | 1 + pages/post/_slug/index.vue | 4 ++++ pages/post/_slug/more-info.vue | 1 + pages/profile/_slug.vue | 1 + 8 files changed, 17 insertions(+), 4 deletions(-) diff --git a/components/Author.vue b/components/Author.vue index f1f57113b..5f1ac9980 100644 --- a/components/Author.vue +++ b/components/Author.vue @@ -107,6 +107,7 @@ diff --git a/components/FollowButton.vue b/components/FollowButton.vue index 3540726d2..0e02f963f 100644 --- a/components/FollowButton.vue +++ b/components/FollowButton.vue @@ -1,6 +1,6 @@ @@ -79,3 +82,9 @@ export default { } } + + diff --git a/locales/de.json b/locales/de.json index b6da57bd9..9821086e6 100644 --- a/locales/de.json +++ b/locales/de.json @@ -22,6 +22,9 @@ "following": "Folgst", "unfollow": "Entfolgen" }, + "shoutButton": { + "shouted": "empfohlen" + }, "profile": { "name": "Mein Profil", "memberSince": "Mitglied seit", diff --git a/locales/en.json b/locales/en.json index aec3233b7..52baeb073 100644 --- a/locales/en.json +++ b/locales/en.json @@ -22,6 +22,9 @@ "following": "Following", "unfollow": "Unfollow" }, + "shoutButton": { + "shouted": "shouted" + }, "profile": { "name": "My Profile", "memberSince": "Member since", From d30649164a475d4816671f6735c68c7f7a2fa27b Mon Sep 17 00:00:00 2001 From: Grzegorz Leoniec Date: Tue, 5 Mar 2019 17:19:35 +0100 Subject: [PATCH 10/14] Improved following and shout behavior --- components/FollowButton.vue | 21 ++++++++++++--------- components/ShoutButton.vue | 19 +++++++++++++++---- locales/de.json | 3 +-- locales/en.json | 3 +-- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/components/FollowButton.vue b/components/FollowButton.vue index c4d0caf24..653ecd2e1 100644 --- a/components/FollowButton.vue +++ b/components/FollowButton.vue @@ -6,7 +6,7 @@ :primary="isFollowed && !hovered" :danger="isFollowed && hovered" fullwidth - @mouseenter.native="hovered = !disabled" + @mouseenter.native="onHover" @mouseleave.native="hovered = false" @click.prevent="toggle" > @@ -40,9 +40,7 @@ export default { } }, label() { - if (this.isFollowed && this.hovered) { - return this.$t('followButton.unfollow') - } else if (this.isFollowed) { + if (this.isFollowed) { return this.$t('followButton.following') } else { return this.$t('followButton.follow') @@ -52,14 +50,20 @@ export default { watch: { isFollowed() { this.loading = false + this.hovered = false } }, methods: { + onHover() { + if (!this.disabled && !this.loading) { + this.hovered = true + } + }, toggle() { const follow = !this.isFollowed const mutation = follow ? 'follow' : 'unfollow' - this.loading = true + this.hovered = false this.$apollo .mutate({ mutation: gql` @@ -72,10 +76,9 @@ export default { } }) .then(res => { - this.$emit('update', !this.isFollowed) - }) - .catch(() => { - this.loading = false + if (res && res.data) { + this.$emit('update', follow) + } }) } } diff --git a/components/ShoutButton.vue b/components/ShoutButton.vue index 9ca77bf5a..95322be4e 100644 --- a/components/ShoutButton.vue +++ b/components/ShoutButton.vue @@ -58,7 +58,14 @@ export default { const mutation = shout ? 'shout' : 'unshout' const count = shout ? this.shoutedCount + 1 : this.shoutedCount - 1 - this.loading = true + const backup = { + shoutedCount: this.shoutedCount, + shouted: this.shouted + } + + this.shoutedCount = count + this.shouted = shout + this.$apollo .mutate({ mutation: gql` @@ -71,9 +78,13 @@ export default { } }) .then(res => { - this.shoutedCount = count - this.shouted = shout - this.$emit('update') + if (res && res.data) { + this.$emit('update') + } + }) + .catch(() => { + this.shoutedCount = backup.shoutedCount + this.shouted = backup.shouted }) .finally(() => { this.loading = false diff --git a/locales/de.json b/locales/de.json index 9821086e6..7a06b767e 100644 --- a/locales/de.json +++ b/locales/de.json @@ -19,8 +19,7 @@ }, "followButton": { "follow": "Folgen", - "following": "Folgst", - "unfollow": "Entfolgen" + "following": "Folge Ich" }, "shoutButton": { "shouted": "empfohlen" diff --git a/locales/en.json b/locales/en.json index 52baeb073..c49fd1318 100644 --- a/locales/en.json +++ b/locales/en.json @@ -19,8 +19,7 @@ }, "followButton": { "follow": "Follow", - "following": "Following", - "unfollow": "Unfollow" + "following": "Following" }, "shoutButton": { "shouted": "shouted" From d9b633c5aecac2b74b76408b2e27abb570a2b069 Mon Sep 17 00:00:00 2001 From: Grzegorz Leoniec Date: Tue, 5 Mar 2019 17:26:20 +0100 Subject: [PATCH 11/14] Make follow button update instant --- components/Author.vue | 2 +- components/FollowButton.vue | 8 ++++++++ components/ShoutButton.vue | 2 +- pages/profile/_slug.vue | 7 ++----- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/components/Author.vue b/components/Author.vue index 6389e36ca..f12e53d3e 100644 --- a/components/Author.vue +++ b/components/Author.vue @@ -108,7 +108,7 @@ diff --git a/components/FollowButton.vue b/components/FollowButton.vue index 653ecd2e1..7cce2e65a 100644 --- a/components/FollowButton.vue +++ b/components/FollowButton.vue @@ -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) + }) } } } diff --git a/components/ShoutButton.vue b/components/ShoutButton.vue index 95322be4e..02d7cb639 100644 --- a/components/ShoutButton.vue +++ b/components/ShoutButton.vue @@ -79,7 +79,7 @@ export default { }) .then(res => { if (res && res.data) { - this.$emit('update') + this.$emit('update', shout) } }) .catch(() => { diff --git a/pages/profile/_slug.vue b/pages/profile/_slug.vue index e6d0f473b..5880921c0 100644 --- a/pages/profile/_slug.vue +++ b/pages/profile/_slug.vue @@ -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()" />