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

39 wiersze
1.0 KiB
Vue
Czysty Zwykły widok Historia

2022-07-11 00:31:08 +00:00
<script setup lang="ts">
import type { User } from '~/types'
import { hashCode, intToRGB } from '~/utils/color'
import { computed } from 'vue'
interface Props {
user: User
avatar?: boolean
}
const props = withDefaults(defineProps<Props>(), {
avatar: true
})
const userColor = computed(() => intToRGB(hashCode(props.user.username + props.user.id)))
const defaultAvatarStyle = computed(() => ({ backgroundColor: `#${userColor.value}` }))
</script>
2018-07-17 11:09:13 +00:00
<template>
2020-05-15 12:12:36 +00:00
<span class="component-user-link">
2020-01-06 09:16:05 +00:00
<template v-if="avatar">
<img
2021-12-06 10:35:20 +00:00
v-if="user.avatar && user.avatar.urls.medium_square_crop"
v-lazy="$store.getters['instance/absoluteUrl'](user.avatar.urls.medium_square_crop)"
2020-01-06 09:16:05 +00:00
class="ui tiny circular avatar"
alt=""
2021-12-06 10:35:20 +00:00
>
<span
v-else
:style="defaultAvatarStyle"
class="ui circular label"
>{{ user.username[0] }}</span>
2020-01-06 09:16:05 +00:00
&nbsp;
</template>
2022-09-22 23:26:59 +00:00
{{ $t('components.common.UserLink.link.username', {username: user.username}) }}
2018-07-17 11:09:13 +00:00
</span>
</template>