feat(web,server): user avatar color (#4779)

This commit is contained in:
martin 2023-11-14 04:10:35 +01:00 committed by GitHub
parent 14c7187539
commit d25a245049
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
58 changed files with 1123 additions and 141 deletions

View file

@ -1,16 +1,48 @@
<script lang="ts">
import Button from '$lib/components/elements/buttons/button.svelte';
import { AppRoute } from '$lib/constants';
import type { UserResponseDto } from '@api';
import { api, UserAvatarColor, type UserResponseDto } from '@api';
import { createEventDispatcher } from 'svelte';
import Icon from '$lib/components/elements/icon.svelte';
import { fade } from 'svelte/transition';
import UserAvatar from '../user-avatar.svelte';
import { mdiCog, mdiLogout } from '@mdi/js';
import { mdiCog, mdiLogout, mdiPencil } from '@mdi/js';
import { notificationController, NotificationType } from '../notification/notification';
import { handleError } from '$lib/utils/handle-error';
import AvatarSelector from './avatar-selector.svelte';
export let user: UserResponseDto;
let isShowSelectAvatar = false;
const dispatch = createEventDispatcher();
const handleSaveProfile = async (color: UserAvatarColor) => {
try {
if (user.profileImagePath !== '') {
await api.userApi.deleteProfileImage();
}
const { data } = await api.userApi.updateUser({
updateUserDto: {
id: user.id,
email: user.email,
name: user.name,
avatarColor: color,
},
});
user = data;
isShowSelectAvatar = false;
notificationController.show({
message: 'Saved profile',
type: NotificationType.Info,
});
} catch (error) {
handleError(error, 'Unable to save profile');
}
};
</script>
<div
@ -22,8 +54,22 @@
<div
class="mx-4 mt-4 flex flex-col items-center justify-center gap-4 rounded-3xl bg-white p-4 dark:bg-immich-dark-primary/10"
>
<UserAvatar size="xl" {user} />
<div class="relative">
{#key user}
<UserAvatar {user} size="xl" />
<div
class="absolute z-10 bottom-0 right-0 rounded-full w-6 h-6 border dark:border-immich-dark-primary bg-immich-primary"
>
<button
class="flex items-center justify-center w-full h-full text-white"
on:click={() => (isShowSelectAvatar = true)}
>
<Icon path={mdiPencil} />
</button>
</div>
{/key}
</div>
<div>
<p class="text-center text-lg font-medium text-immich-primary dark:text-immich-dark-primary">
{user.name}
@ -51,3 +97,10 @@
>
</div>
</div>
{#if isShowSelectAvatar}
<AvatarSelector
{user}
on:close={() => (isShowSelectAvatar = false)}
on:choose={({ detail: color }) => handleSaveProfile(color)}
/>
{/if}