2022-11-29 05:46:04 +09:00
|
|
|
<script setup lang="ts">
|
2023-01-08 15:21:09 +09:00
|
|
|
import type { mastodon } from 'masto'
|
2022-11-29 05:46:04 +09:00
|
|
|
|
|
|
|
const { tag } = defineProps<{
|
2023-01-08 15:21:09 +09:00
|
|
|
tag: mastodon.v1.Tag
|
2022-11-29 05:46:04 +09:00
|
|
|
}>()
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(event: 'change'): void
|
|
|
|
}>()
|
|
|
|
|
2024-02-22 00:20:08 +09:00
|
|
|
const { client } = useMasto()
|
2022-11-29 05:46:04 +09:00
|
|
|
|
2023-03-31 04:01:24 +09:00
|
|
|
async function toggleFollowTag() {
|
2023-01-24 01:36:28 +09:00
|
|
|
// 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
|
2022-11-29 05:46:04 +09:00
|
|
|
|
2023-01-24 01:36:28 +09:00
|
|
|
// eslint-disable-next-line vue/no-mutating-props
|
|
|
|
tag.following = !tag.following
|
|
|
|
|
|
|
|
try {
|
2023-01-25 06:57:24 +09:00
|
|
|
if (previousFollowingState)
|
2024-02-22 00:20:08 +09:00
|
|
|
await client.value.v1.tags.$select(tag.name).unfollow()
|
2023-01-24 01:36:28 +09:00
|
|
|
else
|
2024-02-22 00:20:08 +09:00
|
|
|
await client.value.v1.tags.$select(tag.name).follow()
|
2023-01-24 01:36:28 +09:00
|
|
|
|
|
|
|
emit('change')
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
// eslint-disable-next-line vue/no-mutating-props
|
|
|
|
tag.following = previousFollowingState
|
|
|
|
}
|
2022-11-29 05:46:04 +09:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<button
|
|
|
|
rounded group focus:outline-none
|
|
|
|
hover:text-primary focus-visible:text-primary
|
2023-01-03 09:16:33 +09:00
|
|
|
:aria-label="tag.following ? $t('tag.unfollow_label', [tag.name]) : $t('tag.follow_label', [tag.name])"
|
2022-11-29 05:46:04 +09:00
|
|
|
@click="toggleFollowTag()"
|
|
|
|
>
|
2023-01-03 09:16:33 +09:00
|
|
|
<CommonTooltip placement="bottom" :content="tag.following ? $t('tag.unfollow') : $t('tag.follow')">
|
2023-03-19 21:24:27 +09:00
|
|
|
<div rounded-full p2 elk-group-hover="bg-orange/10" group-focus-visible="bg-orange/10" group-focus-visible:ring="2 current">
|
2022-11-29 05:46:04 +09:00
|
|
|
<div :class="[tag.following ? 'i-ri:star-fill' : 'i-ri:star-line']" />
|
|
|
|
</div>
|
|
|
|
</CommonTooltip>
|
|
|
|
</button>
|
|
|
|
</template>
|