feat: follow tags from trends page (#1391)
This commit is contained in:
parent
677d6188b4
commit
1a7ae6f0ef
2 changed files with 42 additions and 8 deletions
|
@ -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>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue