elk/components/tag/TagActionButton.vue

38 lines
1,022 B
Vue
Raw Normal View History

2022-11-28 21:46:04 +01:00
<script setup lang="ts">
2023-01-08 07:21:09 +01:00
import type { mastodon } from 'masto'
2022-11-28 21:46:04 +01:00
const { tag } = defineProps<{
2023-01-08 07:21:09 +01:00
tag: mastodon.v1.Tag
2022-11-28 21:46:04 +01:00
}>()
const emit = defineEmits<{
(event: 'change'): void
}>()
2023-01-08 07:21:09 +01:00
const masto = useMasto()
2022-11-28 21:46:04 +01:00
const toggleFollowTag = async () => {
if (tag.following)
2023-01-08 07:21:09 +01:00
await masto.v1.tags.unfollow(tag.name)
2022-11-28 21:46:04 +01:00
else
2023-01-08 07:21:09 +01:00
await masto.v1.tags.follow(tag.name)
2022-11-28 21:46:04 +01:00
emit('change')
}
</script>
<template>
<button
rounded group focus:outline-none
hover:text-primary focus-visible:text-primary
2023-01-09 21:20:26 +01:00
:aria-label="tag.following ? $t('tag_unfollow_label', { tag: tag.name }) : $t('tag_follow_label', { tag: tag.name })"
2022-11-28 21:46:04 +01:00
@click="toggleFollowTag()"
>
2023-01-09 21:20:26 +01:00
<CommonTooltip placement="bottom" :content="tag.following ? $t('tag_unfollow') : $t('tag_follow')">
2022-11-28 21:46:04 +01:00
<div rounded-full p2 group-hover="bg-orange/10" group-focus-visible="bg-orange/10" group-focus-visible:ring="2 current">
<div :class="[tag.following ? 'i-ri:star-fill' : 'i-ri:star-line']" />
</div>
</CommonTooltip>
</button>
</template>