2022-11-23 07:40:20 +09:00
|
|
|
<script setup lang="ts">
|
2022-11-23 08:08:36 +09:00
|
|
|
import type { Account } from 'masto'
|
2022-11-23 07:40:20 +09:00
|
|
|
|
|
|
|
const { account } = defineProps<{
|
|
|
|
account: Account
|
|
|
|
}>()
|
|
|
|
|
2022-11-25 00:48:52 +09:00
|
|
|
const isSelf = $computed(() => currentUser.value?.account.id === account.id)
|
2022-11-26 21:58:10 +09:00
|
|
|
let relationship = $(useRelationship(account))
|
2022-11-23 07:40:20 +09:00
|
|
|
|
|
|
|
async function toggleFollow() {
|
|
|
|
relationship!.following = !relationship!.following
|
2022-11-26 21:58:10 +09:00
|
|
|
try {
|
2022-11-27 00:42:58 +09:00
|
|
|
relationship = await useMasto().accounts[relationship!.following ? 'follow' : 'unfollow'](account.id)
|
2022-11-26 21:58:10 +09:00
|
|
|
}
|
|
|
|
catch {
|
|
|
|
// TODO error handling
|
|
|
|
relationship!.following = !relationship!.following
|
|
|
|
}
|
2022-11-23 07:40:20 +09:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-23 22:59:13 +09:00
|
|
|
<button
|
2022-11-29 02:28:40 +09:00
|
|
|
v-if="!isSelf && currentUser"
|
2022-11-24 17:54:52 +09:00
|
|
|
flex gap-1 items-center h-fit rounded hover="op100 text-white b-orange" group
|
2022-11-23 22:59:13 +09:00
|
|
|
@click="toggleFollow"
|
|
|
|
>
|
2022-11-24 17:54:52 +09: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-23 07:40:20 +09:00
|
|
|
<template v-if="relationship?.following">
|
2022-11-26 02:39:50 +09:00
|
|
|
<span group-hover="hidden">{{ relationship?.followedBy ? 'Mutuals' : 'Following' }}</span>
|
2022-11-23 07:40:20 +09:00
|
|
|
<span hidden group-hover="inline">Unfollow</span>
|
|
|
|
</template>
|
2022-11-24 17:54:52 +09: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-23 07:40:20 +09:00
|
|
|
<template v-else>
|
2022-11-24 17:54:52 +09:00
|
|
|
<span>Follow</span>
|
2022-11-23 07:40:20 +09:00
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</template>
|