2023-05-16 16:13:20 +02:00
|
|
|
<script lang="ts">
|
2023-07-01 00:50:47 -04:00
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
|
import AlbumSelectionModal from '$lib/components/shared-components/album-selection-modal.svelte';
|
|
|
|
|
import MenuOption from '$lib/components/shared-components/context-menu/menu-option.svelte';
|
|
|
|
|
import {
|
|
|
|
|
NotificationType,
|
|
|
|
|
notificationController,
|
|
|
|
|
} from '$lib/components/shared-components/notification/notification';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { AppRoute } from '$lib/constants';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { addAssetsToAlbum } from '$lib/utils/asset-utils';
|
2024-02-14 06:38:57 -08:00
|
|
|
import { createAlbum, type AlbumResponseDto } from '@immich/sdk';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { getMenuContext } from '../asset-select-context-menu.svelte';
|
|
|
|
|
import { getAssetControlContext } from '../asset-select-control-bar.svelte';
|
2023-05-16 16:13:20 +02:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
export let shared = false;
|
|
|
|
|
let showAlbumPicker = false;
|
2023-05-16 16:13:20 +02:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const { getAssets, clearSelect } = getAssetControlContext();
|
|
|
|
|
const closeMenu = getMenuContext();
|
2023-05-16 16:13:20 +02:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const handleHideAlbumPicker = () => {
|
|
|
|
|
showAlbumPicker = false;
|
|
|
|
|
closeMenu();
|
|
|
|
|
};
|
2023-05-16 16:13:20 +02:00
|
|
|
|
2023-12-15 03:54:21 +01:00
|
|
|
const handleAddToNewAlbum = (albumName: string) => {
|
2023-07-01 00:50:47 -04:00
|
|
|
showAlbumPicker = false;
|
2023-05-16 16:13:20 +02:00
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
const assetIds = [...getAssets()].map((asset) => asset.id);
|
2024-02-13 17:07:37 -05:00
|
|
|
createAlbum({ createAlbumDto: { albumName, assetIds } }).then((response) => {
|
|
|
|
|
const { id, albumName } = response;
|
2023-05-16 16:13:20 +02:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
notificationController.show({
|
|
|
|
|
message: `Added ${assetIds.length} to ${albumName}`,
|
|
|
|
|
type: NotificationType.Info,
|
|
|
|
|
});
|
2023-05-16 16:13:20 +02:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
clearSelect();
|
2023-05-16 16:13:20 +02:00
|
|
|
|
2023-12-12 03:35:57 +01:00
|
|
|
goto(`${AppRoute.ALBUMS}/${id}`);
|
2023-07-01 00:50:47 -04:00
|
|
|
});
|
|
|
|
|
};
|
2023-05-16 16:13:20 +02:00
|
|
|
|
2023-12-15 03:54:21 +01:00
|
|
|
const handleAddToAlbum = async (album: AlbumResponseDto) => {
|
2023-07-01 00:50:47 -04:00
|
|
|
showAlbumPicker = false;
|
2024-02-02 04:18:00 +01:00
|
|
|
const assetIds = [...getAssets()].map((asset) => asset.id);
|
2023-08-01 21:29:14 -04:00
|
|
|
await addAssetsToAlbum(album.id, assetIds);
|
|
|
|
|
clearSelect();
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
2023-05-16 16:13:20 +02:00
|
|
|
</script>
|
|
|
|
|
|
2023-09-12 16:26:53 +02:00
|
|
|
<MenuOption on:click={() => (showAlbumPicker = true)} text={shared ? 'Add to Shared Album' : 'Add to Album'} />
|
2023-05-16 16:13:20 +02:00
|
|
|
|
|
|
|
|
{#if showAlbumPicker}
|
2023-07-01 00:50:47 -04:00
|
|
|
<AlbumSelectionModal
|
|
|
|
|
{shared}
|
2023-12-15 03:54:21 +01:00
|
|
|
on:newAlbum={({ detail }) => handleAddToNewAlbum(detail)}
|
|
|
|
|
on:album={({ detail }) => handleAddToAlbum(detail)}
|
2023-07-01 00:50:47 -04:00
|
|
|
on:close={handleHideAlbumPicker}
|
|
|
|
|
/>
|
2023-05-16 16:13:20 +02:00
|
|
|
{/if}
|