2022-07-23 13:08:49 -05:00
|
|
|
<script lang="ts">
|
2024-04-25 06:19:49 +02:00
|
|
|
import {
|
2024-05-26 18:15:52 -04:00
|
|
|
getMyUser,
|
2024-04-25 06:19:49 +02:00
|
|
|
removeUserFromAlbum,
|
|
|
|
|
type AlbumResponseDto,
|
|
|
|
|
type UserResponseDto,
|
|
|
|
|
updateAlbumUser,
|
|
|
|
|
AlbumUserRole,
|
|
|
|
|
} from '@immich/sdk';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { mdiDotsVertical } from '@mdi/js';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { createEventDispatcher, onMount } from 'svelte';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { getContextMenuPosition } from '../../utils/context-menu';
|
|
|
|
|
import { handleError } from '../../utils/handle-error';
|
2023-07-01 00:50:47 -04:00
|
|
|
import CircleIconButton from '../elements/buttons/circle-icon-button.svelte';
|
2024-05-28 09:10:43 +07:00
|
|
|
import ConfirmDialog from '../shared-components/dialog/confirm-dialog.svelte';
|
2023-07-01 00:50:47 -04:00
|
|
|
import ContextMenu from '../shared-components/context-menu/context-menu.svelte';
|
|
|
|
|
import MenuOption from '../shared-components/context-menu/menu-option.svelte';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { NotificationType, notificationController } from '../shared-components/notification/notification';
|
|
|
|
|
import UserAvatar from '../shared-components/user-avatar.svelte';
|
2024-04-16 05:06:15 +00:00
|
|
|
import FullScreenModal from '$lib/components/shared-components/full-screen-modal.svelte';
|
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
|
|
|
|
2023-08-11 12:00:51 -04:00
|
|
|
const dispatch = createEventDispatcher<{
|
|
|
|
|
remove: string;
|
2024-04-25 06:19:49 +02:00
|
|
|
refreshAlbum: void;
|
2023-08-11 12:00:51 -04:00
|
|
|
}>();
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
|
let currentUser: UserResponseDto;
|
|
|
|
|
let position = { x: 0, y: 0 };
|
|
|
|
|
let selectedMenuUser: UserResponseDto | null = null;
|
|
|
|
|
let selectedRemoveUser: UserResponseDto | null = null;
|
|
|
|
|
|
|
|
|
|
$: isOwned = currentUser?.id == album.ownerId;
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
try {
|
2024-05-26 18:15:52 -04:00
|
|
|
currentUser = await getMyUser();
|
2024-02-02 04:18:00 +01:00
|
|
|
} catch (error) {
|
|
|
|
|
handleError(error, 'Unable to refresh user');
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-09-29 13:41:58 -04:00
|
|
|
const showContextMenu = (event: MouseEvent, user: UserResponseDto) => {
|
|
|
|
|
position = getContextMenuPosition(event);
|
2023-07-01 00:50:47 -04:00
|
|
|
selectedMenuUser = user;
|
|
|
|
|
selectedRemoveUser = null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleMenuRemove = () => {
|
|
|
|
|
selectedRemoveUser = selectedMenuUser;
|
|
|
|
|
selectedMenuUser = null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleRemoveUser = async () => {
|
|
|
|
|
if (!selectedRemoveUser) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const userId = selectedRemoveUser.id === currentUser?.id ? 'me' : selectedRemoveUser.id;
|
|
|
|
|
|
|
|
|
|
try {
|
2024-02-13 17:07:37 -05:00
|
|
|
await removeUserFromAlbum({ id: album.id, userId });
|
2023-08-11 12:00:51 -04:00
|
|
|
dispatch('remove', userId);
|
2023-11-11 20:03:32 -05:00
|
|
|
const message = userId === 'me' ? `Left ${album.albumName}` : `Removed ${selectedRemoveUser.name}`;
|
2023-07-01 00:50:47 -04:00
|
|
|
notificationController.show({ type: NotificationType.Info, message });
|
2024-02-02 04:18:00 +01:00
|
|
|
} catch (error) {
|
|
|
|
|
handleError(error, 'Unable to remove user');
|
2023-07-01 00:50:47 -04:00
|
|
|
} finally {
|
|
|
|
|
selectedRemoveUser = null;
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-04-25 06:19:49 +02:00
|
|
|
|
|
|
|
|
const handleSetReadonly = async (user: UserResponseDto, role: AlbumUserRole) => {
|
|
|
|
|
try {
|
|
|
|
|
await updateAlbumUser({ id: album.id, userId: user.id, updateAlbumUserDto: { role } });
|
|
|
|
|
const message = `Set ${user.name} as ${role}`;
|
|
|
|
|
dispatch('refreshAlbum');
|
|
|
|
|
notificationController.show({ type: NotificationType.Info, message });
|
|
|
|
|
} catch (error) {
|
|
|
|
|
handleError(error, 'Unable to set user role');
|
|
|
|
|
} finally {
|
|
|
|
|
selectedRemoveUser = null;
|
|
|
|
|
}
|
|
|
|
|
};
|
2022-07-23 13:08:49 -05:00
|
|
|
</script>
|
|
|
|
|
|
2023-06-07 10:37:25 -04:00
|
|
|
{#if !selectedRemoveUser}
|
2024-06-01 22:58:35 +00:00
|
|
|
<FullScreenModal title="Options" {onClose}>
|
2023-07-18 13:19:39 -05:00
|
|
|
<section class="immich-scrollbar max-h-[400px] overflow-y-auto pb-4">
|
2023-08-11 12:00:51 -04:00
|
|
|
<div class="flex w-full place-items-center justify-between gap-4 p-5">
|
|
|
|
|
<div class="flex place-items-center gap-4">
|
2023-11-14 04:10:35 +01:00
|
|
|
<UserAvatar user={album.owner} size="md" />
|
2023-11-11 20:03:32 -05:00
|
|
|
<p class="text-sm font-medium">{album.owner.name}</p>
|
2023-08-11 12:00:51 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div id="icon-{album.owner.id}" class="flex place-items-center">
|
|
|
|
|
<p class="text-sm">Owner</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-04-25 06:19:49 +02:00
|
|
|
{#each album.albumUsers as { user, role }}
|
2023-07-01 00:50:47 -04:00
|
|
|
<div
|
2024-04-16 05:06:15 +00:00
|
|
|
class="flex w-full place-items-center justify-between gap-4 p-5 rounded-xl transition-colors hover:bg-gray-50 dark:hover:bg-gray-700"
|
2023-07-01 00:50:47 -04:00
|
|
|
>
|
2023-07-18 13:19:39 -05:00
|
|
|
<div class="flex place-items-center gap-4">
|
2023-11-14 04:10:35 +01:00
|
|
|
<UserAvatar {user} size="md" />
|
2023-11-11 20:03:32 -05:00
|
|
|
<p class="text-sm font-medium">{user.name}</p>
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
|
|
|
|
|
2024-04-25 06:19:49 +02:00
|
|
|
<div id="icon-{user.id}" class="flex place-items-center gap-2 text-sm">
|
|
|
|
|
<div>
|
|
|
|
|
{#if role === AlbumUserRole.Viewer}
|
|
|
|
|
Viewer
|
|
|
|
|
{:else}
|
|
|
|
|
Editor
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
2023-07-01 00:50:47 -04:00
|
|
|
{#if isOwned}
|
|
|
|
|
<div>
|
|
|
|
|
<CircleIconButton
|
2024-03-29 12:48:07 +00:00
|
|
|
title="Options"
|
2023-09-29 13:41:58 -04:00
|
|
|
on:click={(event) => showContextMenu(event, user)}
|
2023-10-25 09:48:25 -04:00
|
|
|
icon={mdiDotsVertical}
|
2023-07-01 00:50:47 -04:00
|
|
|
size="20"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{#if selectedMenuUser === user}
|
|
|
|
|
<ContextMenu {...position} on:outclick={() => (selectedMenuUser = null)}>
|
2024-04-25 06:19:49 +02:00
|
|
|
{#if role === AlbumUserRole.Viewer}
|
|
|
|
|
<MenuOption on:click={() => handleSetReadonly(user, AlbumUserRole.Editor)} text="Allow edits" />
|
|
|
|
|
{:else}
|
|
|
|
|
<MenuOption
|
|
|
|
|
on:click={() => handleSetReadonly(user, AlbumUserRole.Viewer)}
|
|
|
|
|
text="Disallow edits"
|
|
|
|
|
/>
|
|
|
|
|
{/if}
|
2023-07-01 00:50:47 -04:00
|
|
|
<MenuOption on:click={handleMenuRemove} text="Remove" />
|
|
|
|
|
</ContextMenu>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
{:else if user.id == currentUser?.id}
|
|
|
|
|
<button
|
2024-05-27 09:06:15 +02:00
|
|
|
type="button"
|
2023-07-01 00:50:47 -04:00
|
|
|
on:click={() => (selectedRemoveUser = user)}
|
2023-07-18 13:19:39 -05:00
|
|
|
class="text-sm font-medium text-immich-primary transition-colors hover:text-immich-primary/75 dark:text-immich-dark-primary"
|
2023-07-01 00:50:47 -04:00
|
|
|
>Leave</button
|
|
|
|
|
>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{/each}
|
|
|
|
|
</section>
|
2024-04-16 05:06:15 +00:00
|
|
|
</FullScreenModal>
|
2023-06-07 10:37:25 -04:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
{#if selectedRemoveUser && selectedRemoveUser?.id === currentUser?.id}
|
2024-05-28 09:10:43 +07:00
|
|
|
<ConfirmDialog
|
2024-04-08 21:02:09 +00:00
|
|
|
title="Leave album?"
|
2023-07-01 00:50:47 -04:00
|
|
|
prompt="Are you sure you want to leave {album.albumName}?"
|
|
|
|
|
confirmText="Leave"
|
2024-03-07 04:18:53 +01:00
|
|
|
onConfirm={handleRemoveUser}
|
2024-05-28 09:10:43 +07:00
|
|
|
onCancel={() => (selectedRemoveUser = null)}
|
2023-07-01 00:50:47 -04:00
|
|
|
/>
|
2023-06-07 10:37:25 -04:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
{#if selectedRemoveUser && selectedRemoveUser?.id !== currentUser?.id}
|
2024-05-28 09:10:43 +07:00
|
|
|
<ConfirmDialog
|
2024-04-08 21:02:09 +00:00
|
|
|
title="Remove user?"
|
2024-04-11 09:01:16 +00:00
|
|
|
prompt="Are you sure you want to remove {selectedRemoveUser.name}?"
|
2023-07-01 00:50:47 -04:00
|
|
|
confirmText="Remove"
|
2024-03-07 04:18:53 +01:00
|
|
|
onConfirm={handleRemoveUser}
|
2024-05-28 09:10:43 +07:00
|
|
|
onCancel={() => (selectedRemoveUser = null)}
|
2023-07-01 00:50:47 -04:00
|
|
|
/>
|
2023-06-07 10:37:25 -04:00
|
|
|
{/if}
|