2023-09-24 15:22:46 +02:00
|
|
|
<script lang="ts">
|
2024-04-05 21:19:26 +02:00
|
|
|
import AlbumCover from '$lib/components/album-page/album-cover.svelte';
|
2025-03-14 09:38:06 -04:00
|
|
|
import { handleError } from '$lib/utils/handle-error';
|
|
|
|
|
import { updateAlbumInfo, type AlbumResponseDto } from '@immich/sdk';
|
2025-05-19 09:32:23 -05:00
|
|
|
import { Button, Modal, ModalBody, ModalFooter } from '@immich/ui';
|
2025-03-14 09:38:06 -04:00
|
|
|
import { mdiRenameOutline } from '@mdi/js';
|
2024-06-04 21:53:00 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2023-09-24 15:22:46 +02:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
interface Props {
|
|
|
|
|
album: AlbumResponseDto;
|
|
|
|
|
onEditSuccess?: ((album: AlbumResponseDto) => unknown) | undefined;
|
|
|
|
|
onCancel?: (() => unknown) | undefined;
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
}
|
2023-09-24 15:22:46 +02:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let { album = $bindable(), onEditSuccess = undefined, onCancel = undefined, onClose }: Props = $props();
|
2023-09-24 15:22:46 +02:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let albumName = $state(album.albumName);
|
|
|
|
|
let description = $state(album.description);
|
|
|
|
|
|
|
|
|
|
let isSubmitting = $state(false);
|
2024-04-05 21:19:26 +02:00
|
|
|
|
|
|
|
|
const handleUpdateAlbumInfo = async () => {
|
|
|
|
|
isSubmitting = true;
|
2023-09-24 15:22:46 +02:00
|
|
|
try {
|
2024-02-13 17:07:37 -05:00
|
|
|
await updateAlbumInfo({
|
2023-09-24 15:22:46 +02:00
|
|
|
id: album.id,
|
|
|
|
|
updateAlbumDto: {
|
2024-04-05 21:19:26 +02:00
|
|
|
albumName,
|
|
|
|
|
description,
|
2023-09-24 15:22:46 +02:00
|
|
|
},
|
|
|
|
|
});
|
2024-04-05 21:19:26 +02:00
|
|
|
album.albumName = albumName;
|
|
|
|
|
album.description = description;
|
|
|
|
|
onEditSuccess?.(album);
|
2023-09-24 15:22:46 +02:00
|
|
|
} catch (error) {
|
2024-06-24 15:50:01 +02:00
|
|
|
handleError(error, $t('errors.unable_to_update_album_info'));
|
2024-04-05 21:19:26 +02:00
|
|
|
} finally {
|
|
|
|
|
isSubmitting = false;
|
2023-09-24 15:22:46 +02:00
|
|
|
}
|
|
|
|
|
};
|
2024-11-14 08:43:25 -06:00
|
|
|
|
|
|
|
|
const onsubmit = async (event: Event) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
await handleUpdateAlbumInfo();
|
|
|
|
|
};
|
2023-09-24 15:22:46 +02:00
|
|
|
</script>
|
|
|
|
|
|
2025-05-19 09:32:23 -05:00
|
|
|
<Modal icon={mdiRenameOutline} title={$t('edit_album')} size="medium" {onClose}>
|
|
|
|
|
<ModalBody>
|
|
|
|
|
<form {onsubmit} autocomplete="off" id="edit-album-form">
|
|
|
|
|
<div class="flex items-center">
|
|
|
|
|
<div class="hidden sm:flex">
|
|
|
|
|
<AlbumCover {album} class="h-[200px] w-[200px] m-4 shadow-lg" />
|
2024-04-16 05:06:15 +00:00
|
|
|
</div>
|
2023-09-24 15:22:46 +02:00
|
|
|
|
2025-05-19 09:32:23 -05:00
|
|
|
<div class="grow">
|
|
|
|
|
<div class="m-4 flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="name">{$t('name')}</label>
|
|
|
|
|
<input class="immich-form-input" id="name" type="text" bind:value={albumName} />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="m-4 flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="description">{$t('description')}</label>
|
|
|
|
|
<textarea class="immich-form-input" id="description" bind:value={description}></textarea>
|
|
|
|
|
</div>
|
2024-04-16 05:06:15 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-05-19 09:32:23 -05:00
|
|
|
</form>
|
|
|
|
|
</ModalBody>
|
2024-11-14 08:43:25 -06:00
|
|
|
|
2025-05-19 09:32:23 -05:00
|
|
|
<ModalFooter>
|
|
|
|
|
<div class="flex gap-2 w-full">
|
|
|
|
|
<Button shape="round" color="secondary" fullWidth onclick={() => onCancel?.()}>{$t('cancel')}</Button>
|
|
|
|
|
<Button shape="round" type="submit" fullWidth disabled={isSubmitting} form="edit-album-form">{$t('save')}</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</ModalFooter>
|
|
|
|
|
</Modal>
|