account-info-panel.svelte 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <script lang="ts">
  2. import { UserResponseDto } from '@api';
  3. import { createEventDispatcher } from 'svelte';
  4. import { page } from '$app/stores';
  5. import { fade } from 'svelte/transition';
  6. import Cog from 'svelte-material-icons/Cog.svelte';
  7. import Logout from 'svelte-material-icons/Logout.svelte';
  8. import { goto } from '$app/navigation';
  9. import Button from '$lib/components/elements/buttons/button.svelte';
  10. export let user: UserResponseDto;
  11. // Show fallback while loading profile picture and hide when image loads.
  12. let showProfilePictureFallback = true;
  13. const dispatch = createEventDispatcher();
  14. const getFirstLetter = (text?: string) => {
  15. return text?.charAt(0).toUpperCase();
  16. };
  17. </script>
  18. <div
  19. in:fade={{ duration: 100 }}
  20. out:fade={{ duration: 100 }}
  21. id="account-info-panel"
  22. class="absolute right-[25px] top-[75px] bg-gray-200 dark:bg-immich-dark-gray dark:border dark:border-immich-dark-gray shadow-lg rounded-3xl w-[360px] text-center z-[100]"
  23. >
  24. <div class="bg-white dark:bg-immich-dark-primary/10 rounded-3xl mx-4 mt-4 pb-4">
  25. <div class="flex place-items-center place-content-center">
  26. <div
  27. class="flex place-items-center place-content-center rounded-full bg-immich-primary dark:bg-immich-dark-primary dark:immich-dark-primary/80 h-20 w-20 text-gray-100 hover:bg-immich-primary dark:text-immich-dark-bg mt-4 select-none"
  28. >
  29. {#if user.profileImagePath}
  30. <img
  31. transition:fade={{ duration: 100 }}
  32. class:hidden={showProfilePictureFallback}
  33. src={`${$page.url.origin}/api/user/profile-image/${user.id}`}
  34. alt="profile-img"
  35. class="inline rounded-full h-20 w-20 object-cover shadow-md border-2 border-immich-primary dark:border-immich-dark-primary"
  36. draggable="false"
  37. on:load={() => (showProfilePictureFallback = false)}
  38. />
  39. {/if}
  40. {#if showProfilePictureFallback}
  41. <div transition:fade={{ duration: 200 }} class="text-lg">
  42. {getFirstLetter(user.firstName)}{getFirstLetter(user.lastName)}
  43. </div>
  44. {/if}
  45. </div>
  46. </div>
  47. <p class="text-lg text-immich-primary dark:text-immich-dark-primary font-medium mt-4">
  48. {user.firstName}
  49. {user.lastName}
  50. </p>
  51. <p class="text-sm text-gray-500 dark:text-immich-dark-fg">{user.email}</p>
  52. <div class="mt-4">
  53. <Button
  54. color="dark-gray"
  55. size="sm"
  56. shadow={false}
  57. border
  58. on:click={() => {
  59. goto('/user-settings');
  60. dispatch('close');
  61. }}
  62. >
  63. <div class="flex gap-2 place-items-center place-content-center px-2">
  64. <Cog size="18" />
  65. Account Settings
  66. </div>
  67. </Button>
  68. </div>
  69. </div>
  70. <div class="mb-4 flex flex-col">
  71. <button
  72. class="py-3 w-full font-medium flex place-items-center gap-2 hover:bg-immich-primary/10 text-gray-500 dark:text-gray-300 place-content-center"
  73. on:click={() => dispatch('logout')}
  74. >
  75. <Logout size={24} />
  76. Sign Out</button
  77. >
  78. </div>
  79. </div>