forked from Mirrors/elk
feat: avoid follow button flash on hover card (#308)
This commit is contained in:
parent
73f1f1d151
commit
3d395a02ec
2 changed files with 19 additions and 13 deletions
|
@ -1,23 +1,25 @@
|
|||
<script setup lang="ts">
|
||||
import type { Account } from 'masto'
|
||||
import type { Account, Relationship } from 'masto'
|
||||
|
||||
const { account, command } = defineProps<{
|
||||
const { account, command, ...props } = defineProps<{
|
||||
account: Account
|
||||
relationship?: Relationship
|
||||
command?: boolean
|
||||
}>()
|
||||
|
||||
const isSelf = $computed(() => currentUser.value?.account.id === account.id)
|
||||
const enable = $computed(() => !isSelf && currentUser.value)
|
||||
let relationship = $(useRelationship(account))
|
||||
const relationship = $$(props.relationship) ?? useRelationship(account)
|
||||
|
||||
async function toggleFollow() {
|
||||
relationship!.following = !relationship!.following
|
||||
const rel = relationship.value
|
||||
rel!.following = !rel!.following
|
||||
try {
|
||||
relationship = await useMasto().accounts[relationship!.following ? 'follow' : 'unfollow'](account.id)
|
||||
relationship.value = await useMasto().accounts[rel!.following ? 'follow' : 'unfollow'](account.id)
|
||||
}
|
||||
catch {
|
||||
// TODO error handling
|
||||
relationship!.following = !relationship!.following
|
||||
rel!.following = !rel!.following
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,19 +29,21 @@ useCommand({
|
|||
scope: 'Actions',
|
||||
order: -2,
|
||||
visible: () => command && enable,
|
||||
name: () => `${relationship?.following ? t('account.unfollow') : t('account.follow')} ${getShortHandle(account)}`,
|
||||
name: () => `${relationship.value?.following ? t('account.unfollow') : t('account.follow')} ${getShortHandle(account)}`,
|
||||
icon: 'i-ri:star-line',
|
||||
onActivate: () => toggleFollow(),
|
||||
})
|
||||
|
||||
const buttonStyle = $computed(() => {
|
||||
const rel = relationship.value
|
||||
|
||||
// Skeleton while loading, avoid primary color flash
|
||||
if (!relationship)
|
||||
if (!rel)
|
||||
return 'text-inverted'
|
||||
|
||||
// If following, use a label style with a strong border for Mutuals
|
||||
if (relationship.following)
|
||||
return `text-base ${relationship.followedBy ? 'border-strong' : 'border-base'}`
|
||||
if (rel.following)
|
||||
return `text-base ${rel.followedBy ? 'border-strong' : 'border-base'}`
|
||||
|
||||
// If not following, use a button style
|
||||
return 'text-inverted bg-primary border-primary'
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
<script setup lang="ts">
|
||||
import type { Account } from 'masto'
|
||||
|
||||
defineProps<{
|
||||
const { account } = defineProps<{
|
||||
account: Account
|
||||
}>()
|
||||
|
||||
const relationship = $(useRelationship(account))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div flex="~ col gap2" rounded min-w-90 max-w-120 z-100 overflow-hidden p-4>
|
||||
<div v-show="relationship" flex="~ col gap2" rounded min-w-90 max-w-120 z-100 overflow-hidden p-4>
|
||||
<div flex="~ gap2" items-center>
|
||||
<NuxtLink :to="getAccountRoute(account)" flex-auto rounded-full hover:bg-active transition-100 pr5 mr-a>
|
||||
<AccountInfo :account="account" />
|
||||
</NuxtLink>
|
||||
<AccountFollowButton text-sm :account="account" />
|
||||
<AccountFollowButton text-sm :account="account" :relationship="relationship" />
|
||||
</div>
|
||||
<ContentRich text-4 text-secondary :content="account.note" :emojis="account.emojis" />
|
||||
<AccountPostsFollowers text-sm :account="account" />
|
||||
|
|
Loading…
Reference in a new issue