2022-05-21 02:23:55 -05:00
< script lang = "ts" >
2022-12-17 16:08:18 -06:00
import NavigationBar from '$lib/components/shared-components/navigation-bar/navigation-bar.svelte';
2022-07-16 23:52:00 -05:00
import SideBar from '$lib/components/shared-components/side-bar/side-bar.svelte';
2022-09-04 08:34:39 -05:00
import AssetGrid from '$lib/components/photos-page/asset-grid.svelte';
2022-11-04 23:29:48 -04:00
import ContextMenu from '$lib/components/shared-components/context-menu/context-menu.svelte';
import MenuOption from '$lib/components/shared-components/context-menu/menu-option.svelte';
import AlbumSelectionModal from '$lib/components/shared-components/album-selection-modal.svelte';
import { goto } from '$app/navigation';
2022-09-04 08:34:39 -05:00
2022-08-24 21:10:48 -07:00
import type { PageData } from './$types';
2022-08-26 22:53:37 -07:00
2022-12-30 04:07:18 +02:00
import { openFileUploadDialog } from '$lib/utils/file-uploader';
2022-09-04 08:34:39 -05:00
import {
assetInteractionStore,
isMultiSelectStoreState,
selectedAssets
} from '$lib/stores/asset-interaction.store';
import ControlAppBar from '$lib/components/shared-components/control-app-bar.svelte';
import Close from 'svelte-material-icons/Close.svelte';
2023-01-09 14:16:08 -06:00
import CloudDownloadOutline from 'svelte-material-icons/CloudDownloadOutline.svelte';
2022-09-04 08:34:39 -05:00
import CircleIconButton from '$lib/components/shared-components/circle-icon-button.svelte';
import DeleteOutline from 'svelte-material-icons/DeleteOutline.svelte';
2022-11-04 23:29:48 -04:00
import Plus from 'svelte-material-icons/Plus.svelte';
import { AlbumResponseDto , api } from '@api';
2022-08-26 10:36:41 -07:00
import {
notificationController,
NotificationType
} from '$lib/components/shared-components/notification/notification';
2022-09-04 08:34:39 -05:00
import { assetStore } from '$lib/stores/assets.store';
2023-01-09 14:16:08 -06:00
import { addAssetsToAlbum , bulkDownload } from '$lib/utils/asset-utils';
2022-05-21 02:23:55 -05:00
2022-08-24 21:10:48 -07:00
export let data: PageData;
2022-07-08 21:26:50 -05:00
2022-08-08 22:06:11 -05:00
const deleteSelectedAssetHandler = async () => {
try {
if (
window.confirm(
2022-09-04 08:34:39 -05:00
`Caution! Are you sure you want to delete ${ $selectedAssets . size } assets? This step also deletes assets in the album(s) to which they belong. You can not undo this action!`
2022-08-08 22:06:11 -05:00
)
) {
const { data : deletedAssets } = await api.assetApi.deleteAsset({
2022-09-04 08:34:39 -05:00
ids: Array.from($selectedAssets).map((a) => a.id)
2022-08-08 22:06:11 -05:00
});
for (const asset of deletedAssets) {
if (asset.status == 'SUCCESS') {
2022-09-04 08:34:39 -05:00
assetStore.removeAsset(asset.id);
2022-08-08 22:06:11 -05:00
}
}
2022-09-04 08:34:39 -05:00
assetInteractionStore.clearMultiselect();
2022-08-08 22:06:11 -05:00
}
} catch (e) {
2022-08-26 10:36:41 -07:00
notificationController.show({
type: NotificationType.Error,
message: 'Error deleting assets, check console for more details'
});
console.error('Error deleteSelectedAssetHandler', e);
2022-08-08 22:06:11 -05:00
}
};
2022-11-04 23:29:48 -04:00
let contextMenuPosition = { x : 0 , y : 0 } ;
let isShowAddMenu = false;
let isShowAlbumPicker = false;
let addToSharedAlbum = false;
const handleShowMenu = (event: CustomEvent) => {
contextMenuPosition = {
x: event.detail.mouseEvent.x,
y: event.detail.mouseEvent.y
};
isShowAddMenu = !isShowAddMenu;
};
const handleShowAlbumPicker = (shared: boolean) => {
isShowAddMenu = false;
isShowAlbumPicker = true;
addToSharedAlbum = shared;
};
2023-01-09 22:24:07 +02:00
const handleAddToNewAlbum = (event: CustomEvent) => {
2022-11-04 23:29:48 -04:00
isShowAlbumPicker = false;
2023-01-09 22:24:07 +02:00
const { albumName } : { albumName : string } = event.detail;
2022-11-04 23:29:48 -04:00
const assetIds = Array.from($selectedAssets).map((asset) => asset.id);
2023-01-09 22:24:07 +02:00
api.albumApi.createAlbum({ albumName , assetIds } ).then((response) => {
2022-11-04 23:29:48 -04:00
const { id , albumName } = response.data;
notificationController.show({
message: `Added ${ assetIds . length } to ${ albumName } `,
type: NotificationType.Info
});
assetInteractionStore.clearMultiselect();
goto('/albums/' + id);
});
};
const handleAddToAlbum = async (event: CustomEvent< { album : AlbumResponseDto } >) => {
isShowAlbumPicker = false;
const album = event.detail.album;
const assetIds = Array.from($selectedAssets).map((asset) => asset.id);
2022-12-30 04:07:18 +02:00
addAssetsToAlbum(album.id, assetIds).then(() => {
2022-11-04 23:29:48 -04:00
assetInteractionStore.clearMultiselect();
});
};
2023-01-09 14:16:08 -06:00
const handleDownloadFiles = async () => {
await bulkDownload('immich', Array.from($selectedAssets), () => {
assetInteractionStore.clearMultiselect();
});
};
2022-05-21 02:23:55 -05:00
< / script >
< section >
2022-09-04 08:34:39 -05:00
{ #if $isMultiSelectStoreState }
2022-08-08 22:06:11 -05:00
< ControlAppBar
2022-09-04 08:34:39 -05:00
on:close-button-click={() => assetInteractionStore . clearMultiselect ()}
2022-08-08 22:06:11 -05:00
backIcon={ Close }
tailwindClasses={ 'bg-white shadow-md' }
>
< svelte:fragment slot = "leading" >
2022-10-26 11:10:48 -05:00
< p class = "font-medium text-immich-primary dark:text-immich-dark-primary" >
Selected { $selectedAssets . size }
< / p >
2022-08-08 22:06:11 -05:00
< / svelte:fragment >
< svelte:fragment slot = "trailing" >
2023-01-09 14:16:08 -06:00
< CircleIconButton
title="Download"
logo={ CloudDownloadOutline }
on:click={ handleDownloadFiles }
/>
2022-11-04 23:29:48 -04:00
< CircleIconButton title = "Add" logo = { Plus } on:click= { handleShowMenu } />
2022-08-08 22:06:11 -05:00
< CircleIconButton
title="Delete"
logo={ DeleteOutline }
on:click={ deleteSelectedAssetHandler }
/>
< / svelte:fragment >
< / ControlAppBar >
2022-09-04 08:34:39 -05:00
{ : else }
2022-12-30 04:07:18 +02:00
< NavigationBar user = { data . user } on:uploadClicked= {() => openFileUploadDialog ()} />
2022-08-08 22:06:11 -05:00
{ /if }
2022-11-04 23:29:48 -04:00
{ #if isShowAddMenu }
< ContextMenu {... contextMenuPosition } on:clickoutside = {() => ( isShowAddMenu = false )} >
< div class = "flex flex-col rounded-lg " >
< MenuOption on:click = {() => handleShowAlbumPicker ( false )} text="Add to Album " />
< MenuOption on:click = {() => handleShowAlbumPicker ( true )} text="Add to Shared Album " />
< / div >
< / ContextMenu >
{ /if }
{ #if isShowAlbumPicker }
< AlbumSelectionModal
shared={ addToSharedAlbum }
on:newAlbum={ handleAddToNewAlbum }
on:newSharedAlbum={ handleAddToNewAlbum }
on:album={ handleAddToAlbum }
on:close={() => ( isShowAlbumPicker = false )}
/>
{ /if }
2022-05-21 02:23:55 -05:00
< / section >
2022-10-26 11:10:48 -05:00
< section
class="grid grid-cols-[250px_auto] relative pt-[72px] h-screen bg-immich-bg dark:bg-immich-dark-bg"
>
2022-07-15 23:18:17 -05:00
< SideBar / >
2022-09-04 08:34:39 -05:00
< AssetGrid / >
2022-05-21 02:23:55 -05:00
< / section >