elk/components/account/AccountFollowRequestButton.vue

69 lines
1.9 KiB
Vue
Raw Permalink Normal View History

2023-10-22 19:11:00 +03:00
<script setup lang="ts">
import type { mastodon } from 'masto'
const { account, ...props } = defineProps<{
account: mastodon.v1.Account
relationship?: mastodon.v1.Relationship
}>()
const relationship = computed(() => props.relationship || useRelationship(account).value)
const { client } = useMasto()
2023-10-22 19:11:00 +03:00
async function authorizeFollowRequest() {
relationship.value!.requestedBy = false
relationship.value!.followedBy = true
2023-10-22 19:11:00 +03:00
try {
const newRel = await client.value.v1.followRequests.$select(account.id).authorize()
2023-10-22 19:11:00 +03:00
Object.assign(relationship!, newRel)
}
catch (err) {
console.error(err)
relationship.value!.requestedBy = true
relationship.value!.followedBy = false
2023-10-22 19:11:00 +03:00
}
}
async function rejectFollowRequest() {
relationship.value!.requestedBy = false
2023-10-22 19:11:00 +03:00
try {
const newRel = await client.value.v1.followRequests.$select(account.id).reject()
2023-10-22 19:11:00 +03:00
Object.assign(relationship!, newRel)
}
catch (err) {
console.error(err)
relationship.value!.requestedBy = true
2023-10-22 19:11:00 +03:00
}
}
</script>
<template>
<div flex gap-4>
<template v-if="relationship?.requestedBy">
<CommonTooltip :content="$t('account.authorize')">
2023-10-22 19:11:00 +03:00
<button
type="button"
rounded-full text-sm p2 border-1
hover:text-green transition-colors
@click="authorizeFollowRequest"
>
<span block text-current i-ri:check-fill />
</button>
</CommonTooltip>
<CommonTooltip :content="$t('account.reject')">
2023-10-22 19:11:00 +03:00
<button
type="button"
rounded-full text-sm p2 border-1
hover:text-red transition-colors
@click="rejectFollowRequest"
>
<span block text-current i-ri:close-fill />
</button>
</CommonTooltip>
</template>
<template v-else>
<span text-secondary>
{{ relationship?.followedBy ? $t('account.authorized') : $t('account.rejected') }}
</span>
</template>
</div>
</template>