elk/components/account/AccountFollowButton.vue

38 lines
1.3 KiB
Vue
Raw Normal View History

2022-11-22 22:40:20 +00:00
<script setup lang="ts">
2022-11-22 23:08:36 +00:00
import type { Account } from 'masto'
2022-11-22 22:40:20 +00:00
const { account } = defineProps<{
account: Account
}>()
const isSelf = $computed(() => currentUser.value?.account?.id === account.id)
2022-11-22 22:40:20 +00:00
const relationship = $(useRelationship(account))
async function toggleFollow() {
relationship!.following = !relationship!.following
await masto.accounts[relationship!.following ? 'follow' : 'unfollow'](account.id)
}
</script>
<template>
<button
v-if="!isSelf && relationship"
2022-11-24 08:54:52 +00:00
flex gap-1 items-center h-fit rounded hover="op100 text-white b-orange" group
@click="toggleFollow"
>
2022-11-24 08:54:52 +00:00
<div rounded w-28 p2 :group-hover="relationship?.following ? 'bg-red/75' : 'bg-orange/40'" :class="!relationship?.following ? relationship?.followedBy ? 'bg-orange/20' : 'bg-white/10' : relationship?.followedBy ? ' bg-orange/70' : 'bg-orange/50'">
2022-11-22 22:40:20 +00:00
<template v-if="relationship?.following">
2022-11-24 08:54:52 +00:00
<span group-hover="hidden">{{ relationship?.followedBy ? 'Mutual' : 'Following' }}</span>
2022-11-22 22:40:20 +00:00
<span hidden group-hover="inline">Unfollow</span>
</template>
2022-11-24 08:54:52 +00:00
<template v-else-if="relationship?.followedBy">
<span group-hover="hidden">Follows you</span>
<span hidden group-hover="inline">Follow back</span>
</template>
2022-11-22 22:40:20 +00:00
<template v-else>
2022-11-24 08:54:52 +00:00
<span>Follow</span>
2022-11-22 22:40:20 +00:00
</template>
</div>
</button>
</template>