Improved follow button optimistic behavior

This commit is contained in:
Grzegorz Leoniec 2019-03-05 17:35:41 +01:00
parent d9b633c5ae
commit 8792f02932
No known key found for this signature in database
GPG Key ID: 3AA43686D4EB1377
3 changed files with 5 additions and 7 deletions

View File

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

View File

@ -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)
})
}
}

View File

@ -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()"
/>
</ds-space>
<template v-if="user.about">