funkwhale/front/src/components/common/ActorLink.vue

65 wiersze
1.3 KiB
Vue
Czysty Zwykły widok Historia

2022-04-30 20:46:37 +00:00
<script setup lang="ts">
import { toRefs } from '@vueuse/core'
import { computed } from 'vue'
import { truncate } from '~/utils/filters'
import { Actor } from '~/types'
interface Props {
actor: Actor
avatar?: boolean
admin?: boolean
displayName?: boolean
truncateLength?: number
}
const { displayName, actor, truncateLength, admin, avatar } = toRefs(withDefaults(
defineProps<Props>(),
{
avatar: true,
admin: false,
displayName: false,
truncateLength: 30
}
))
const repr = computed(() => {
const name = displayName.value || actor.value.is_local
? actor.value.preferred_username
: actor.value.full_username
return truncate(name, truncateLength.value)
})
const url = computed(() => {
if (admin.value) {
return { name: 'manage.moderation.accounts.detail', params: { id: actor.value.full_username } }
}
if (actor.value.is_local) {
return { name: 'profile.overview', params: { username: actor.value.preferred_username } }
}
return {
name: 'profile.full.overview',
params: {
username: actor.value.preferred_username,
domain: actor.value.domain
}
}
})
</script>
<template>
2021-12-06 10:35:20 +00:00
<router-link
:to="url"
:title="actor.full_username"
>
2022-04-30 20:46:37 +00:00
<actor-avatar
v-if="avatar"
:actor="actor"
/>
<span>&nbsp;</span>
<slot>{{ repr }}</slot>
</router-link>
</template>