mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-07 09:29:59 +00:00
parent
33a51b65b4
commit
1476438d73
1 changed files with 9 additions and 11 deletions
|
@ -9,17 +9,17 @@ const { account, command, ...props } = defineProps<{
|
||||||
|
|
||||||
const isSelf = $computed(() => currentUser.value?.account.id === account.id)
|
const isSelf = $computed(() => currentUser.value?.account.id === account.id)
|
||||||
const enable = $computed(() => !isSelf && currentUser.value)
|
const enable = $computed(() => !isSelf && currentUser.value)
|
||||||
const relationship = $$(props.relationship) ?? useRelationship(account)
|
const relationship = $computed(() => props.relationship || useRelationship(account).value)
|
||||||
|
|
||||||
async function toggleFollow() {
|
async function toggleFollow() {
|
||||||
const rel = relationship.value
|
relationship!.following = !relationship!.following
|
||||||
rel!.following = !rel!.following
|
|
||||||
try {
|
try {
|
||||||
relationship.value = await useMasto().accounts[rel!.following ? 'follow' : 'unfollow'](account.id)
|
const newRel = await useMasto().accounts[relationship!.following ? 'follow' : 'unfollow'](account.id)
|
||||||
|
Object.assign(relationship!, newRel)
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
// TODO error handling
|
// TODO error handling
|
||||||
rel!.following = !rel!.following
|
relationship!.following = !relationship!.following
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,21 +29,19 @@ useCommand({
|
||||||
scope: 'Actions',
|
scope: 'Actions',
|
||||||
order: -2,
|
order: -2,
|
||||||
visible: () => command && enable,
|
visible: () => command && enable,
|
||||||
name: () => `${relationship.value?.following ? t('account.unfollow') : t('account.follow')} ${getShortHandle(account)}`,
|
name: () => `${relationship?.following ? t('account.unfollow') : t('account.follow')} ${getShortHandle(account)}`,
|
||||||
icon: 'i-ri:star-line',
|
icon: 'i-ri:star-line',
|
||||||
onActivate: () => toggleFollow(),
|
onActivate: () => toggleFollow(),
|
||||||
})
|
})
|
||||||
|
|
||||||
const buttonStyle = $computed(() => {
|
const buttonStyle = $computed(() => {
|
||||||
const rel = relationship.value
|
|
||||||
|
|
||||||
// Skeleton while loading, avoid primary color flash
|
// Skeleton while loading, avoid primary color flash
|
||||||
if (!rel)
|
if (!relationship)
|
||||||
return 'text-inverted'
|
return 'text-inverted'
|
||||||
|
|
||||||
// If following, use a label style with a strong border for Mutuals
|
// If following, use a label style with a strong border for Mutuals
|
||||||
if (rel.following)
|
if (relationship.following)
|
||||||
return `text-base ${rel.followedBy ? 'border-strong' : 'border-base'}`
|
return `text-base ${relationship.followedBy ? 'border-strong' : 'border-base'}`
|
||||||
|
|
||||||
// If not following, use a button style
|
// If not following, use a button style
|
||||||
return 'text-inverted bg-primary border-primary'
|
return 'text-inverted bg-primary border-primary'
|
||||||
|
|
Loading…
Reference in a new issue