feat: follow tags from trends page (#1391)

This commit is contained in:
Shinigami 2023-01-23 17:36:28 +01:00 committed by GitHub
parent 677d6188b4
commit 1a7ae6f0ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 8 deletions

View file

@ -12,12 +12,24 @@ const emit = defineEmits<{
const { client } = $(useMasto())
const toggleFollowTag = async () => {
if (tag.following)
await client.v1.tags.unfollow(tag.name)
else
await client.v1.tags.follow(tag.name)
// We save the state so be can do an optimistic UI update, but fallback to the previous state if the API call fails
const previousFollowingState = tag.following
emit('change')
// eslint-disable-next-line vue/no-mutating-props
tag.following = !tag.following
try {
if (tag.following)
await client.v1.tags.unfollow(tag.name)
else
await client.v1.tags.follow(tag.name)
emit('change')
}
catch (error) {
// eslint-disable-next-line vue/no-mutating-props
tag.following = previousFollowingState
}
}
</script>