mealie/frontend/components/Domain/User/UserAvatar.vue
Hoa (Kyle) Trinh c24d532608
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Docker Nightly Production / Backend Server Tests (push) Waiting to run
Docker Nightly Production / Frontend Tests (push) Waiting to run
Docker Nightly Production / Build Package (push) Waiting to run
Docker Nightly Production / Build Tagged Release (push) Blocked by required conditions
Docker Nightly Production / Notify Discord (push) Blocked by required conditions
Release Drafter / ✏️ Draft release (push) Waiting to run
feat: Migrate to Nuxt 3 framework (#5184)
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
2025-06-19 17:09:12 +00:00

85 lines
1.7 KiB
Vue

<template>
<v-tooltip
v-if="userId"
:disabled="!user || !tooltip"
right
>
<template #activator="{ props }">
<v-avatar
v-if="list"
v-bind="props"
>
<v-img
:src="imageURL"
:alt="userId"
@load="error = false"
@error="error = true"
/>
</v-avatar>
<v-avatar
v-else
:size="size"
v-bind="props"
>
<v-img
:src="imageURL"
:alt="userId"
@load="error = false"
@error="error = true"
/>
</v-avatar>
</template>
<span v-if="user">
{{ user.fullName }}
</span>
</v-tooltip>
</template>
<script lang="ts">
import { useUserStore } from "~/composables/store/use-user-store";
export default defineNuxtComponent({
props: {
userId: {
type: String,
required: true,
},
list: {
type: Boolean,
default: false,
},
size: {
type: String,
default: "42",
},
tooltip: {
type: Boolean,
default: true,
},
},
setup(props) {
const state = reactive({
error: false,
});
const $auth = useMealieAuth();
const { store: users } = useUserStore();
const user = computed(() => {
return users.value.find(user => user.id === props.userId);
});
const imageURL = computed(() => {
// Note: $auth.user is a ref now
const authUser = $auth.user.value;
const key = authUser?.cacheKey ?? "";
return `/api/media/users/${props.userId}/profile.webp?cacheKey=${key}`;
});
return {
user,
imageURL,
...toRefs(state),
};
},
});
</script>