elk/components/account/AccountFollowButton.vue

63 lines
2 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, command } = defineProps<{
2022-11-22 22:40:20 +00:00
account: Account
command?: boolean
2022-11-22 22:40:20 +00:00
}>()
2022-11-24 15:48:52 +00:00
const isSelf = $computed(() => currentUser.value?.account.id === account.id)
const enable = $computed(() => !isSelf && currentUser.value)
2022-11-26 12:58:10 +00:00
let relationship = $(useRelationship(account))
2022-11-22 22:40:20 +00:00
async function toggleFollow() {
relationship!.following = !relationship!.following
2022-11-26 12:58:10 +00:00
try {
relationship = await useMasto().accounts[relationship!.following ? 'follow' : 'unfollow'](account.id)
2022-11-26 12:58:10 +00:00
}
catch {
// TODO error handling
relationship!.following = !relationship!.following
}
2022-11-22 22:40:20 +00:00
}
useCommand({
scope: 'Actions',
order: -2,
visible: () => command && enable,
name: () => `${relationship?.following ? 'Unfollow' : 'Follow'} ${getShortHandle(account)}`,
icon: 'i-ri:star-line',
onActivate: () => toggleFollow(),
})
2022-11-22 22:40:20 +00:00
</script>
<template>
<button
v-if="enable"
flex gap-1 items-center h-fit rounded hover="op100 text-white b-orange" group btn-base
:disabled="relationship?.requested"
@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-25 17:39:50 +00:00
<span group-hover="hidden">{{ relationship?.followedBy ? 'Mutuals' : 'Following' }}</span>
2022-11-29 06:57:32 +00:00
<span hidden group-hover="inline">{{ $t('account.unfollow') }}</span>
2022-11-22 22:40:20 +00:00
</template>
<template v-else-if="relationship?.requested">
2022-11-29 06:57:32 +00:00
<span>{{ $t('account.follow_requested') }}</span>
</template>
2022-11-24 08:54:52 +00:00
<template v-else-if="relationship?.followedBy">
2022-11-29 06:57:32 +00:00
<span group-hover="hidden">{{ $t('account.follows_you') }}</span>
<span hidden group-hover="inline">{{ $t('account.follow_back') }}</span>
2022-11-24 08:54:52 +00:00
</template>
2022-11-22 22:40:20 +00:00
<template v-else>
2022-11-29 06:57:32 +00:00
<span>{{ $t('account.follow') }}</span>
2022-11-22 22:40:20 +00:00
</template>
</div>
</button>
</template>