2022-05-21 02:23:55 -05:00
|
|
|
<script lang="ts">
|
2022-06-03 11:04:30 -05:00
|
|
|
import { goto } from '$app/navigation';
|
2022-05-21 02:23:55 -05:00
|
|
|
import { page } from '$app/stores';
|
2022-06-19 08:16:35 -05:00
|
|
|
import { createEventDispatcher, onMount } from 'svelte';
|
2022-09-08 17:30:49 +02:00
|
|
|
import { fade, fly } from 'svelte/transition';
|
2022-06-19 08:16:35 -05:00
|
|
|
import TrayArrowUp from 'svelte-material-icons/TrayArrowUp.svelte';
|
2022-07-15 23:18:17 -05:00
|
|
|
import { clickOutside } from '../../utils/click-outside';
|
2022-08-26 10:05:15 -07:00
|
|
|
import { api, UserResponseDto } from '@api';
|
2022-10-26 11:10:48 -05:00
|
|
|
import ThemeButton from './theme-button.svelte';
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2022-08-26 10:05:15 -07:00
|
|
|
export let user: UserResponseDto;
|
|
|
|
export let shouldShowUploadButton = true;
|
2022-05-21 02:23:55 -05:00
|
|
|
|
|
|
|
let shouldShowAccountInfo = false;
|
2022-05-28 22:35:45 -05:00
|
|
|
let shouldShowProfileImage = false;
|
2022-06-19 08:16:35 -05:00
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
2022-06-11 23:17:20 -05:00
|
|
|
let shouldShowAccountInfoPanel = false;
|
2022-05-28 22:35:45 -05:00
|
|
|
|
2022-07-10 21:41:45 -05:00
|
|
|
onMount(() => {
|
|
|
|
getUserProfileImage();
|
2022-05-28 22:35:45 -05:00
|
|
|
});
|
2022-06-03 11:04:30 -05:00
|
|
|
|
2022-07-10 21:41:45 -05:00
|
|
|
const getUserProfileImage = async () => {
|
2022-07-26 12:28:07 -05:00
|
|
|
try {
|
|
|
|
await api.userApi.getProfileImage(user.id);
|
|
|
|
shouldShowProfileImage = true;
|
|
|
|
} catch (e) {
|
|
|
|
shouldShowProfileImage = false;
|
2022-07-10 21:41:45 -05:00
|
|
|
}
|
|
|
|
};
|
2022-05-21 02:23:55 -05:00
|
|
|
const getFirstLetter = (text?: string) => {
|
|
|
|
return text?.charAt(0).toUpperCase();
|
|
|
|
};
|
2022-06-03 11:04:30 -05:00
|
|
|
|
2022-06-11 23:17:20 -05:00
|
|
|
const showAccountInfoPanel = () => {
|
|
|
|
shouldShowAccountInfoPanel = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
const logOut = async () => {
|
2022-11-14 21:24:25 -05:00
|
|
|
const { data } = await api.authenticationApi.logout();
|
|
|
|
|
2022-07-31 16:53:07 -05:00
|
|
|
await fetch('auth/logout', { method: 'POST' });
|
2022-11-14 21:24:25 -05:00
|
|
|
|
|
|
|
goto(data.redirectUri || '/auth/login');
|
2022-06-11 23:17:20 -05:00
|
|
|
};
|
2022-05-21 02:23:55 -05:00
|
|
|
</script>
|
|
|
|
|
2022-10-26 11:10:48 -05:00
|
|
|
<section
|
|
|
|
id="dashboard-navbar"
|
|
|
|
class="fixed w-screen z-[100] bg-immich-bg dark:bg-immich-dark-bg text-sm"
|
|
|
|
>
|
|
|
|
<div class="flex border-b dark:border-b-immich-dark-gray place-items-center px-6 py-2 ">
|
2022-09-16 23:13:22 -05:00
|
|
|
<a
|
|
|
|
data-sveltekit-prefetch
|
|
|
|
class="flex gap-2 place-items-center hover:cursor-pointer"
|
|
|
|
href="/photos"
|
|
|
|
>
|
2022-05-21 02:23:55 -05:00
|
|
|
<img src="/immich-logo.svg" alt="immich logo" height="35" width="35" />
|
2022-10-26 11:10:48 -05:00
|
|
|
<h1 class="font-immich-title text-2xl text-immich-primary dark:text-immich-dark-primary">
|
|
|
|
IMMICH
|
|
|
|
</h1>
|
2022-05-21 02:23:55 -05:00
|
|
|
</a>
|
|
|
|
<div class="flex-1 ml-24">
|
2022-07-22 09:44:22 -05:00
|
|
|
<input
|
2022-10-26 11:10:48 -05:00
|
|
|
class="w-[50%] rounded-md bg-gray-200 dark:bg-immich-dark-gray px-8 py-4"
|
2022-07-22 09:44:22 -05:00
|
|
|
placeholder="Search - Coming soon"
|
|
|
|
/>
|
2022-05-21 02:23:55 -05:00
|
|
|
</div>
|
2022-06-19 08:16:35 -05:00
|
|
|
<section class="flex gap-4 place-items-center">
|
2022-10-26 11:10:48 -05:00
|
|
|
<ThemeButton />
|
|
|
|
|
2022-08-26 10:05:15 -07:00
|
|
|
{#if $page.url.pathname !== '/admin' && shouldShowUploadButton}
|
2022-06-19 08:16:35 -05:00
|
|
|
<button
|
|
|
|
in:fly={{ x: 50, duration: 250 }}
|
|
|
|
on:click={() => dispatch('uploadClicked')}
|
2022-10-26 11:10:48 -05:00
|
|
|
class="immich-text-button dark:hover:bg-immich-dark-primary/25 dark:text-immich-dark-fg"
|
2022-06-19 08:16:35 -05:00
|
|
|
>
|
|
|
|
<TrayArrowUp size="20" />
|
|
|
|
<span> Upload </span>
|
|
|
|
</button>
|
|
|
|
{/if}
|
2022-05-21 02:23:55 -05:00
|
|
|
|
|
|
|
{#if user.isAdmin}
|
2022-09-16 23:13:22 -05:00
|
|
|
<a data-sveltekit-prefetch href={`admin`}>
|
2022-07-15 23:18:17 -05:00
|
|
|
<button
|
2022-10-26 11:10:48 -05:00
|
|
|
class={`flex place-items-center place-content-center gap-2 hover:bg-immich-primary/5 dark:hover:bg-immich-dark-primary/25 dark:text-immich-dark-fg p-2 rounded-lg font-medium ${
|
|
|
|
$page.url.pathname == '/admin' &&
|
|
|
|
'text-immich-primary dark:immich-dark-primary underline'
|
2022-07-15 23:18:17 -05:00
|
|
|
}`}>Administration</button
|
|
|
|
>
|
|
|
|
</a>
|
2022-05-21 02:23:55 -05:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
<div
|
|
|
|
on:mouseover={() => (shouldShowAccountInfo = true)}
|
|
|
|
on:focus={() => (shouldShowAccountInfo = true)}
|
|
|
|
on:mouseleave={() => (shouldShowAccountInfo = false)}
|
2022-06-11 23:17:20 -05:00
|
|
|
on:click={showAccountInfoPanel}
|
2022-05-21 02:23:55 -05:00
|
|
|
>
|
|
|
|
<button
|
2022-10-26 11:10:48 -05:00
|
|
|
class="flex place-items-center place-content-center rounded-full bg-immich-primary hover:bg-immich-primary/80 h-12 w-12 text-gray-100 dark:text-immich-dark-bg dark:bg-immich-dark-primary"
|
2022-05-21 02:23:55 -05:00
|
|
|
>
|
2022-05-28 22:35:45 -05:00
|
|
|
{#if shouldShowProfileImage}
|
|
|
|
<img
|
2022-08-06 23:42:50 -05:00
|
|
|
src={`api/user/profile-image/${user.id}`}
|
2022-05-28 22:35:45 -05:00
|
|
|
alt="profile-img"
|
|
|
|
class="inline rounded-full h-12 w-12 object-cover shadow-md"
|
|
|
|
/>
|
|
|
|
{:else}
|
|
|
|
{getFirstLetter(user.firstName)}{getFirstLetter(user.lastName)}
|
|
|
|
{/if}
|
2022-05-21 02:23:55 -05:00
|
|
|
</button>
|
|
|
|
|
|
|
|
{#if shouldShowAccountInfo}
|
|
|
|
<div
|
|
|
|
in:fade={{ delay: 500, duration: 150 }}
|
|
|
|
out:fade={{ delay: 200, duration: 150 }}
|
2022-10-26 11:10:48 -05:00
|
|
|
class="absolute -bottom-12 right-5 border bg-gray-500 dark:bg-immich-dark-gray text-[12px] text-gray-100 p-2 rounded-md shadow-md dark:border-immich-dark-gray"
|
2022-05-21 02:23:55 -05:00
|
|
|
>
|
|
|
|
<p>{user.firstName} {user.lastName}</p>
|
|
|
|
<p>{user.email}</p>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
2022-06-11 23:17:20 -05:00
|
|
|
|
|
|
|
{#if shouldShowAccountInfoPanel}
|
|
|
|
<div
|
|
|
|
in:fade={{ duration: 100 }}
|
|
|
|
out:fade={{ duration: 100 }}
|
|
|
|
id="account-info-panel"
|
2022-10-26 11:10:48 -05:00
|
|
|
class="absolute right-[25px] top-[75px] bg-immich-bg dark:bg-immich-dark-gray dark:border dark:border-immich-dark-gray shadow-lg rounded-2xl w-[360px] text-center z-[100]"
|
2022-06-11 23:17:20 -05:00
|
|
|
use:clickOutside
|
2022-07-15 23:18:17 -05:00
|
|
|
on:out-click={() => (shouldShowAccountInfoPanel = false)}
|
2022-06-11 23:17:20 -05:00
|
|
|
>
|
|
|
|
<div class="flex place-items-center place-content-center mt-6">
|
|
|
|
<button
|
2022-10-26 11:10:48 -05:00
|
|
|
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"
|
2022-06-11 23:17:20 -05:00
|
|
|
>
|
|
|
|
{#if shouldShowProfileImage}
|
|
|
|
<img
|
2022-08-07 08:12:31 -05:00
|
|
|
src={`api/user/profile-image/${user.id}`}
|
2022-06-11 23:17:20 -05:00
|
|
|
alt="profile-img"
|
|
|
|
class="inline rounded-full h-20 w-20 object-cover shadow-md"
|
|
|
|
/>
|
|
|
|
{:else}
|
|
|
|
<div class="text-lg">
|
|
|
|
{getFirstLetter(user.firstName)}{getFirstLetter(user.lastName)}
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
2022-10-26 11:10:48 -05:00
|
|
|
<p class="text-lg text-immich-primary dark:text-immich-dark-primary font-medium mt-4">
|
2022-06-11 23:17:20 -05:00
|
|
|
{user.firstName}
|
|
|
|
{user.lastName}
|
|
|
|
</p>
|
|
|
|
|
2022-10-26 11:10:48 -05:00
|
|
|
<p class="text-sm text-gray-500 dark:text-immich-dark-fg">{user.email}</p>
|
2022-06-11 23:17:20 -05:00
|
|
|
|
|
|
|
<div class="my-4">
|
2022-10-26 11:10:48 -05:00
|
|
|
<hr class="dark:border-immich-dark-bg" />
|
2022-06-11 23:17:20 -05:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="mb-6">
|
2022-10-26 11:10:48 -05:00
|
|
|
<button
|
|
|
|
class="border rounded-3xl px-6 py-2 hover:bg-gray-50 dark:border-immich-dark-gray dark:bg-gray-300 dark:hover:bg-immich-dark-primary"
|
|
|
|
on:click={logOut}>Sign Out</button
|
2022-07-22 09:44:22 -05:00
|
|
|
>
|
2022-06-11 23:17:20 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/if}
|
2022-05-21 02:23:55 -05:00
|
|
|
</section>
|