From 48dc087e58c099b1346fc81c80c77d517b105e11 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Tue, 3 Apr 2018 09:51:34 -0700 Subject: [PATCH] be optimistic about follow button --- .../_components/profile/AccountProfileFollow.html | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/routes/_components/profile/AccountProfileFollow.html b/routes/_components/profile/AccountProfileFollow.html index 71888261..b4404207 100644 --- a/routes/_components/profile/AccountProfileFollow.html +++ b/routes/_components/profile/AccountProfileFollow.html @@ -28,12 +28,16 @@ async onFollowButtonClick(e) { e.preventDefault() e.stopPropagation() + let account = this.get('account') let accountId = this.get('accountId') - let instanceName = this.store.get('currentInstance') let following = this.get('following') let followRequested = this.get('followRequested') this.set({animateFollowButton: true}) - await setAccountFollowed(accountId, !(following || followRequested)) + let newFollowingValue = !(following || followRequested) + await setAccountFollowed(accountId, newFollowingValue) + if (!account.locked) { // be optimistic, show the user that it succeeded + this.set({overrideFollowing: newFollowingValue) + } } }, store: () => store, @@ -42,7 +46,12 @@ }), computed: { accountId: (account) => account.id, - following: (relationship) => relationship && relationship.following, + following: (relationship, overrideFollowing) => { + if (typeof overrideFollowing === 'boolean') { + return overrideFollowing + } + return relationship && relationship.following + }, followRequested: (relationship, account) => { return relationship && relationship.requested && account && account.locked },