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
|
|
|
|
2022-11-29 08:15:05 +00:00
|
|
|
const { account, command } = defineProps<{
|
2022-11-22 22:40:20 +00:00
|
|
|
account: Account
|
2022-11-29 08:15:05 +00:00
|
|
|
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)
|
2022-11-29 08:15:05 +00:00
|
|
|
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 {
|
2022-11-26 15:42:58 +00:00
|
|
|
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
|
|
|
}
|
2022-11-29 08:15:05 +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>
|
2022-11-23 13:59:13 +00:00
|
|
|
<button
|
2022-11-29 08:15:05 +00:00
|
|
|
v-if="enable"
|
2022-11-29 20:04:23 +00:00
|
|
|
gap-1 items-center group
|
2022-11-28 20:56:24 +00:00
|
|
|
:disabled="relationship?.requested"
|
2022-11-29 20:04:23 +00:00
|
|
|
border-1
|
|
|
|
rounded-full flex="~ gap2 center" font-500 w-30 h-fit py1 :class="relationship?.following ? 'text-base border-text-base' : 'text-inverted bg-primary border-primary'" :hover="relationship?.following ? 'border-red text-red' : 'bg-base border-primary text-primary'" @click="toggleFollow"
|
2022-11-23 13:59:13 +00:00
|
|
|
>
|
2022-11-29 20:04:23 +00:00
|
|
|
<template v-if="relationship?.following">
|
|
|
|
<span group-hover="hidden">{{ relationship?.followedBy ? 'Mutuals' : 'Following' }}</span>
|
|
|
|
<span hidden group-hover="inline">{{ $t('account.unfollow') }}</span>
|
|
|
|
</template>
|
|
|
|
<template v-else-if="relationship?.requested">
|
|
|
|
<span>{{ $t('account.follow_requested') }}</span>
|
|
|
|
</template>
|
|
|
|
<template v-else-if="relationship?.followedBy">
|
|
|
|
<span group-hover="hidden">{{ $t('account.follows_you') }}</span>
|
|
|
|
<span hidden group-hover="inline">{{ $t('account.follow_back') }}</span>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<span>{{ $t('account.follow') }}</span>
|
|
|
|
</template>
|
2022-11-22 22:40:20 +00:00
|
|
|
</button>
|
|
|
|
</template>
|