2022-07-22 09:44:22 -05:00
|
|
|
<script lang="ts">
|
2024-04-25 06:19:49 +02:00
|
|
|
import Dropdown from '$lib/components/elements/dropdown.svelte';
|
2024-02-13 17:07:37 -05:00
|
|
|
import Icon from '$lib/components/elements/icon.svelte';
|
2024-04-25 06:19:49 +02:00
|
|
|
import FullScreenModal from '$lib/components/shared-components/full-screen-modal.svelte';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { AppRoute } from '$lib/constants';
|
2024-02-14 08:09:49 -05:00
|
|
|
import {
|
2024-04-25 06:19:49 +02:00
|
|
|
AlbumUserRole,
|
2024-02-14 08:09:49 -05:00
|
|
|
getAllSharedLinks,
|
2024-05-26 18:15:52 -04:00
|
|
|
searchUsers,
|
2024-02-14 08:09:49 -05:00
|
|
|
type AlbumResponseDto,
|
2024-04-25 06:19:49 +02:00
|
|
|
type AlbumUserAddDto,
|
2024-02-14 08:09:49 -05:00
|
|
|
type SharedLinkResponseDto,
|
|
|
|
|
type UserResponseDto,
|
|
|
|
|
} from '@immich/sdk';
|
2024-04-25 06:19:49 +02:00
|
|
|
import { mdiCheck, mdiEye, mdiLink, mdiPencil, mdiShareCircle } from '@mdi/js';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { createEventDispatcher, onMount } from 'svelte';
|
|
|
|
|
import Button from '../elements/buttons/button.svelte';
|
|
|
|
|
import UserAvatar from '../shared-components/user-avatar.svelte';
|
2024-06-04 21:53:00 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
|
export let album: AlbumResponseDto;
|
2024-04-11 09:01:16 +00:00
|
|
|
export let onClose: () => void;
|
2023-07-01 00:50:47 -04:00
|
|
|
let users: UserResponseDto[] = [];
|
2024-04-25 06:19:49 +02:00
|
|
|
let selectedUsers: Record<string, { user: UserResponseDto; role: AlbumUserRole }> = {};
|
|
|
|
|
|
|
|
|
|
const roleOptions: Array<{ title: string; value: AlbumUserRole | 'none'; icon?: string }> = [
|
2024-06-04 21:53:00 +02:00
|
|
|
{ title: $t('editor'), value: AlbumUserRole.Editor, icon: mdiPencil },
|
|
|
|
|
{ title: $t('viewer'), value: AlbumUserRole.Viewer, icon: mdiEye },
|
|
|
|
|
{ title: $t('remove'), value: 'none' },
|
2024-04-25 06:19:49 +02:00
|
|
|
];
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2023-08-11 12:00:51 -04:00
|
|
|
const dispatch = createEventDispatcher<{
|
2024-04-25 06:19:49 +02:00
|
|
|
select: AlbumUserAddDto[];
|
2023-08-11 12:00:51 -04:00
|
|
|
share: void;
|
|
|
|
|
}>();
|
2023-07-01 00:50:47 -04:00
|
|
|
let sharedLinks: SharedLinkResponseDto[] = [];
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
await getSharedLinks();
|
2024-05-26 18:15:52 -04:00
|
|
|
const data = await searchUsers();
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-05-26 18:15:52 -04:00
|
|
|
// remove album owner
|
|
|
|
|
users = data.filter((user) => user.id !== album.ownerId);
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
|
// Remove the existed shared users from the album
|
2024-05-24 15:37:01 +01:00
|
|
|
for (const sharedUser of album.albumUsers) {
|
|
|
|
|
users = users.filter((user) => user.id !== sharedUser.user.id);
|
2024-02-02 04:18:00 +01:00
|
|
|
}
|
2023-07-01 00:50:47 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const getSharedLinks = async () => {
|
2024-02-14 08:09:49 -05:00
|
|
|
const data = await getAllSharedLinks();
|
2023-07-01 00:50:47 -04:00
|
|
|
sharedLinks = data.filter((link) => link.album?.id === album.id);
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-25 06:19:49 +02:00
|
|
|
const handleToggle = (user: UserResponseDto) => {
|
|
|
|
|
if (Object.keys(selectedUsers).includes(user.id)) {
|
|
|
|
|
delete selectedUsers[user.id];
|
|
|
|
|
selectedUsers = selectedUsers;
|
|
|
|
|
} else {
|
|
|
|
|
selectedUsers[user.id] = { user, role: AlbumUserRole.Editor };
|
|
|
|
|
}
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
|
|
|
|
|
2024-04-25 06:19:49 +02:00
|
|
|
const handleChangeRole = (user: UserResponseDto, role: AlbumUserRole | 'none') => {
|
|
|
|
|
if (role === 'none') {
|
|
|
|
|
delete selectedUsers[user.id];
|
|
|
|
|
selectedUsers = selectedUsers;
|
|
|
|
|
} else {
|
|
|
|
|
selectedUsers[user.id].role = role;
|
|
|
|
|
}
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
2022-07-22 09:44:22 -05:00
|
|
|
</script>
|
|
|
|
|
|
2024-06-04 21:53:00 +02:00
|
|
|
<FullScreenModal title={$t('invite_to_album')} showLogo {onClose}>
|
2024-04-25 06:19:49 +02:00
|
|
|
{#if Object.keys(selectedUsers).length > 0}
|
|
|
|
|
<div class="mb-2 py-2 sticky">
|
2024-06-04 21:53:00 +02:00
|
|
|
<p class="text-xs font-medium">{$t('selected').toUpperCase()}</p>
|
2024-04-25 06:19:49 +02:00
|
|
|
<div class="my-2">
|
|
|
|
|
{#each Object.values(selectedUsers) as { user }}
|
|
|
|
|
{#key user.id}
|
|
|
|
|
<div class="flex place-items-center gap-4 p-4">
|
|
|
|
|
<div
|
|
|
|
|
class="flex h-10 w-10 items-center justify-center rounded-full border bg-immich-dark-success text-3xl text-white dark:border-immich-dark-gray dark:bg-immich-dark-success"
|
|
|
|
|
>
|
|
|
|
|
<Icon path={mdiCheck} size={24} />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- <UserAvatar {user} size="md" /> -->
|
|
|
|
|
<div class="text-left flex-grow">
|
|
|
|
|
<p class="text-immich-fg dark:text-immich-dark-fg">
|
|
|
|
|
{user.name}
|
|
|
|
|
</p>
|
|
|
|
|
<p class="text-xs">
|
|
|
|
|
{user.email}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Dropdown
|
2024-06-04 21:53:00 +02:00
|
|
|
title={$t('role')}
|
2024-04-25 06:19:49 +02:00
|
|
|
options={roleOptions}
|
|
|
|
|
render={({ title, icon }) => ({ title, icon })}
|
|
|
|
|
on:select={({ detail: { value } }) => handleChangeRole(user, value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
{/key}
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
2024-01-19 12:27:29 -06:00
|
|
|
</div>
|
|
|
|
|
{/if}
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-04-25 06:19:49 +02:00
|
|
|
{#if users.length + Object.keys(selectedUsers).length === 0}
|
|
|
|
|
<p class="p-5 text-sm">
|
|
|
|
|
Looks like you have shared this album with all users or you don't have any user to share with.
|
|
|
|
|
</p>
|
|
|
|
|
{/if}
|
|
|
|
|
|
2024-01-19 12:27:29 -06:00
|
|
|
<div class="immich-scrollbar max-h-[500px] overflow-y-auto">
|
2024-04-25 06:19:49 +02:00
|
|
|
{#if users.length > 0 && users.length !== Object.keys(selectedUsers).length}
|
2024-06-04 21:53:00 +02:00
|
|
|
<p class="text-xs font-medium">{$t('suggestions').toUpperCase()}</p>
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-04-25 06:19:49 +02:00
|
|
|
<div class="my-2">
|
2023-07-01 00:50:47 -04:00
|
|
|
{#each users as user}
|
2024-04-25 06:19:49 +02:00
|
|
|
{#if !Object.keys(selectedUsers).includes(user.id)}
|
|
|
|
|
<div class="flex place-items-center transition-all hover:bg-gray-200 dark:hover:bg-gray-700 rounded-xl">
|
2024-05-27 09:06:15 +02:00
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
on:click={() => handleToggle(user)}
|
|
|
|
|
class="flex w-full place-items-center gap-4 p-4"
|
|
|
|
|
>
|
2024-04-25 06:19:49 +02:00
|
|
|
<UserAvatar {user} size="md" />
|
|
|
|
|
<div class="text-left flex-grow">
|
|
|
|
|
<p class="text-immich-fg dark:text-immich-dark-fg">
|
|
|
|
|
{user.name}
|
|
|
|
|
</p>
|
|
|
|
|
<p class="text-xs">
|
|
|
|
|
{user.email}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</button>
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
2024-04-25 06:19:49 +02:00
|
|
|
{/if}
|
2023-07-01 00:50:47 -04:00
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-01-19 12:27:29 -06:00
|
|
|
{#if users.length > 0}
|
2024-04-16 05:06:15 +00:00
|
|
|
<div class="py-3">
|
2024-01-19 12:27:29 -06:00
|
|
|
<Button
|
|
|
|
|
size="sm"
|
|
|
|
|
fullwidth
|
|
|
|
|
rounded="full"
|
2024-04-25 06:19:49 +02:00
|
|
|
disabled={Object.keys(selectedUsers).length === 0}
|
|
|
|
|
on:click={() =>
|
|
|
|
|
dispatch(
|
|
|
|
|
'select',
|
|
|
|
|
Object.values(selectedUsers).map(({ user, ...rest }) => ({ userId: user.id, ...rest })),
|
2024-06-04 21:53:00 +02:00
|
|
|
)}>{$t('add')}</Button
|
2024-01-19 12:27:29 -06:00
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<hr />
|
2024-01-19 12:27:29 -06:00
|
|
|
|
2024-04-16 05:06:15 +00:00
|
|
|
<div id="shared-buttons" class="mt-4 flex place-content-center place-items-center justify-around">
|
2023-07-01 00:50:47 -04:00
|
|
|
<button
|
2024-05-27 09:06:15 +02:00
|
|
|
type="button"
|
2023-07-18 13:19:39 -05:00
|
|
|
class="flex flex-col place-content-center place-items-center gap-2 hover:cursor-pointer"
|
2023-08-11 12:00:51 -04:00
|
|
|
on:click={() => dispatch('share')}
|
2023-07-01 00:50:47 -04:00
|
|
|
>
|
2023-10-25 09:48:25 -04:00
|
|
|
<Icon path={mdiLink} size={24} />
|
2024-06-04 21:53:00 +02:00
|
|
|
<p class="text-sm">{$t('create_link')}</p>
|
2023-07-01 00:50:47 -04:00
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
{#if sharedLinks.length}
|
2024-05-27 09:06:15 +02:00
|
|
|
<a
|
|
|
|
|
href={AppRoute.SHARED_LINKS}
|
2023-07-18 13:19:39 -05:00
|
|
|
class="flex flex-col place-content-center place-items-center gap-2 hover:cursor-pointer"
|
2023-07-01 00:50:47 -04:00
|
|
|
>
|
2023-10-25 09:48:25 -04:00
|
|
|
<Icon path={mdiShareCircle} size={24} />
|
2024-06-04 21:53:00 +02:00
|
|
|
<p class="text-sm">{$t('view_links')}</p>
|
2024-05-27 09:06:15 +02:00
|
|
|
</a>
|
2023-07-01 00:50:47 -04:00
|
|
|
{/if}
|
|
|
|
|
</div>
|
2024-04-16 05:06:15 +00:00
|
|
|
</FullScreenModal>
|