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

41 wiersze
941 B
Vue
Czysty Zwykły widok Historia

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>
@{{ user.username }}
2018-07-17 11:09:13 +00:00
</span>
</template>
<script>
2022-04-23 07:37:43 +00:00
import { hashCode, intToRGB } from '~/utils/color'
2018-07-17 11:09:13 +00:00
export default {
2020-01-06 09:16:05 +00:00
props: {
2021-12-06 10:50:04 +00:00
user: { type: Object, required: true },
2021-12-06 10:35:20 +00:00
avatar: { type: Boolean, default: true }
2020-01-06 09:16:05 +00:00
},
2018-07-17 11:09:13 +00:00
computed: {
userColor () {
return intToRGB(hashCode(this.user.username + String(this.user.id)))
},
defaultAvatarStyle () {
return {
'background-color': `#${this.userColor}`
}
}
}
}
</script>