2022-11-27 05:13:18 +03:00
|
|
|
<script setup lang="ts">
|
2023-01-08 09:21:09 +03:00
|
|
|
import type { mastodon } from 'masto'
|
2024-02-24 15:24:21 +03:00
|
|
|
import { fetchAccountByHandle } from '~/composables/cache'
|
|
|
|
|
2024-03-04 22:20:13 +03:00
|
|
|
type WatcherType = [acc?: mastodon.v1.Account | null, h?: string, v?: boolean]
|
2022-11-27 05:13:18 +03:00
|
|
|
|
2023-07-02 19:26:23 +03:00
|
|
|
defineOptions({
|
|
|
|
inheritAttrs: false,
|
|
|
|
})
|
|
|
|
|
2022-11-30 10:08:10 +03:00
|
|
|
const props = defineProps<{
|
2024-03-04 22:20:13 +03:00
|
|
|
account?: mastodon.v1.Account | null
|
2022-11-30 10:08:10 +03:00
|
|
|
handle?: string
|
2022-11-28 20:24:39 +03:00
|
|
|
disabled?: boolean
|
2022-11-27 05:13:18 +03:00
|
|
|
}>()
|
2022-11-30 10:08:10 +03:00
|
|
|
|
2024-03-04 22:20:13 +03:00
|
|
|
const accountHover = ref()
|
|
|
|
const hovered = useElementHover(accountHover)
|
2024-02-24 15:24:21 +03:00
|
|
|
const account = ref<mastodon.v1.Account | null | undefined>(props.account)
|
|
|
|
|
|
|
|
watch(
|
2024-03-04 22:20:13 +03:00
|
|
|
() => [props.account, props.handle, hovered.value] satisfies WatcherType,
|
2024-02-24 15:24:21 +03:00
|
|
|
([newAccount, newHandle, newVisible], oldProps) => {
|
2024-03-04 22:20:13 +03:00
|
|
|
if (!newVisible || process.test)
|
|
|
|
return
|
|
|
|
|
2024-02-24 15:24:21 +03:00
|
|
|
if (newAccount) {
|
|
|
|
account.value = newAccount
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newHandle) {
|
|
|
|
const [_oldAccount, oldHandle, _oldVisible] = oldProps ?? [undefined, undefined, false]
|
|
|
|
if (!oldHandle || newHandle !== oldHandle || !account.value) {
|
|
|
|
// new handle can be wrong: using server instead of webDomain
|
|
|
|
fetchAccountByHandle(newHandle).then((acc) => {
|
|
|
|
if (newHandle === props.handle)
|
|
|
|
account.value = acc
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
account.value = undefined
|
2024-03-05 17:48:58 +03:00
|
|
|
},
|
|
|
|
{ immediate: true, flush: 'post' },
|
2024-02-24 15:24:21 +03:00
|
|
|
)
|
|
|
|
|
2023-01-24 23:46:33 +03:00
|
|
|
const userSettings = useUserSettings()
|
2022-11-27 05:13:18 +03:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2024-03-04 22:20:13 +03:00
|
|
|
<span ref="accountHover">
|
|
|
|
<VMenu
|
|
|
|
v-if="!disabled && account && !getPreferences(userSettings, 'hideAccountHoverCard')"
|
|
|
|
placement="bottom-start"
|
|
|
|
:delay="{ show: 500, hide: 100 }"
|
|
|
|
v-bind="$attrs"
|
|
|
|
:close-on-content-click="false"
|
2024-04-06 06:58:50 +03:00
|
|
|
no-auto-focus
|
2024-03-04 22:20:13 +03:00
|
|
|
>
|
2024-02-24 15:24:21 +03:00
|
|
|
<slot />
|
|
|
|
<template #popper>
|
|
|
|
<AccountHoverCard v-if="account" :account="account" />
|
|
|
|
</template>
|
|
|
|
</VMenu>
|
|
|
|
<slot v-else />
|
|
|
|
</span>
|
2022-11-27 05:13:18 +03:00
|
|
|
</template>
|