2023-01-14 23:49:47 -06:00
|
|
|
<script lang="ts">
|
2023-07-01 00:50:47 -04:00
|
|
|
import { goto } from '$app/navigation';
|
2024-02-14 08:09:49 -05:00
|
|
|
import { AppRoute } from '$lib/constants';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { dragAndDropFilesStore } from '$lib/stores/drag-and-drop-files.store';
|
2024-02-27 08:37:37 -08:00
|
|
|
import { getKey, handlePromiseError } from '$lib/utils';
|
2024-02-14 08:09:49 -05:00
|
|
|
import { downloadArchive } from '$lib/utils/asset-utils';
|
|
|
|
|
import { fileUploadHandler, openFileUploadDialog } from '$lib/utils/file-uploader';
|
|
|
|
|
import { handleError } from '$lib/utils/handle-error';
|
2024-02-14 06:38:57 -08:00
|
|
|
import { addSharedLinkAssets, type AssetResponseDto, type SharedLinkResponseDto } from '@immich/sdk';
|
2024-02-14 08:09:49 -05:00
|
|
|
import { mdiArrowLeft, mdiFileImagePlusOutline, mdiFolderDownloadOutline, mdiSelectAll } from '@mdi/js';
|
2023-07-01 00:50:47 -04:00
|
|
|
import CircleIconButton from '../elements/buttons/circle-icon-button.svelte';
|
|
|
|
|
import DownloadAction from '../photos-page/actions/download-action.svelte';
|
|
|
|
|
import RemoveFromSharedLink from '../photos-page/actions/remove-from-shared-link.svelte';
|
|
|
|
|
import AssetSelectControlBar from '../photos-page/asset-select-control-bar.svelte';
|
|
|
|
|
import ControlAppBar from '../shared-components/control-app-bar.svelte';
|
|
|
|
|
import GalleryViewer from '../shared-components/gallery-viewer/gallery-viewer.svelte';
|
2024-05-27 21:10:53 -05:00
|
|
|
import ImmichLogoSmallLink from '$lib/components/shared-components/immich-logo-small-link.svelte';
|
2024-02-14 08:09:49 -05:00
|
|
|
import { NotificationType, notificationController } from '../shared-components/notification/notification';
|
2024-02-17 11:00:55 -06:00
|
|
|
import type { Viewport } from '$lib/stores/assets.store';
|
2024-06-04 21:53:00 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2023-01-14 23:49:47 -06:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
interface Props {
|
|
|
|
|
sharedLink: SharedLinkResponseDto;
|
|
|
|
|
isOwned: boolean;
|
|
|
|
|
}
|
2023-01-14 23:49:47 -06:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let { sharedLink = $bindable(), isOwned }: Props = $props();
|
2023-01-14 23:49:47 -06:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
const viewport: Viewport = $state({ width: 0, height: 0 });
|
|
|
|
|
let selectedAssets: Set<AssetResponseDto> = $state(new Set());
|
|
|
|
|
let innerWidth: number = $state(0);
|
|
|
|
|
|
|
|
|
|
let assets = $derived(sharedLink.assets);
|
|
|
|
|
let isMultiSelectionMode = $derived(selectedAssets.size > 0);
|
2023-01-14 23:49:47 -06:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
dragAndDropFilesStore.subscribe((value) => {
|
|
|
|
|
if (value.isDragging && value.files.length > 0) {
|
2024-02-27 08:37:37 -08:00
|
|
|
handlePromiseError(handleUploadAssets(value.files));
|
2023-07-01 00:50:47 -04:00
|
|
|
dragAndDropFilesStore.set({ isDragging: false, files: [] });
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-06-29 17:26:25 +02:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const downloadAssets = async () => {
|
2023-08-25 00:03:28 -04:00
|
|
|
await downloadArchive(`immich-shared.zip`, { assetIds: assets.map((asset) => asset.id) });
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
2023-01-14 23:49:47 -06:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const handleUploadAssets = async (files: File[] = []) => {
|
|
|
|
|
try {
|
|
|
|
|
let results: (string | undefined)[] = [];
|
2024-02-02 04:18:00 +01:00
|
|
|
results = await (!files || files.length === 0 || !Array.isArray(files)
|
|
|
|
|
? openFileUploadDialog()
|
|
|
|
|
: fileUploadHandler(files));
|
2024-02-14 08:09:49 -05:00
|
|
|
const data = await addSharedLinkAssets({
|
2023-07-01 00:50:47 -04:00
|
|
|
id: sharedLink.id,
|
|
|
|
|
assetIdsDto: {
|
|
|
|
|
assetIds: results.filter((id) => !!id) as string[],
|
|
|
|
|
},
|
2024-02-14 08:09:49 -05:00
|
|
|
key: getKey(),
|
2023-07-01 00:50:47 -04:00
|
|
|
});
|
2023-01-14 23:49:47 -06:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const added = data.filter((item) => item.success).length;
|
2023-06-20 21:08:43 -04:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
notificationController.show({
|
2024-06-24 15:50:01 +02:00
|
|
|
message: $t('assets_added_count', { values: { count: added } }),
|
2023-07-01 00:50:47 -04:00
|
|
|
type: NotificationType.Info,
|
|
|
|
|
});
|
2024-02-02 04:18:00 +01:00
|
|
|
} catch (error) {
|
2024-06-24 15:50:01 +02:00
|
|
|
handleError(error, $t('errors.unable_to_add_assets_to_shared_link'));
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
|
};
|
2023-06-29 17:11:37 +02:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const handleSelectAll = () => {
|
|
|
|
|
selectedAssets = new Set(assets);
|
|
|
|
|
};
|
2023-01-14 23:49:47 -06:00
|
|
|
</script>
|
|
|
|
|
|
2024-05-09 09:21:45 -05:00
|
|
|
<svelte:window bind:innerWidth />
|
|
|
|
|
|
2023-01-14 23:49:47 -06:00
|
|
|
<section class="bg-immich-bg dark:bg-immich-dark-bg">
|
2023-07-01 00:50:47 -04:00
|
|
|
{#if isMultiSelectionMode}
|
|
|
|
|
<AssetSelectControlBar assets={selectedAssets} clearSelect={() => (selectedAssets = new Set())}>
|
2024-11-14 08:43:25 -06:00
|
|
|
<CircleIconButton title={$t('select_all')} icon={mdiSelectAll} onclick={handleSelectAll} />
|
2023-07-01 00:50:47 -04:00
|
|
|
{#if sharedLink?.allowDownload}
|
2023-08-25 00:03:28 -04:00
|
|
|
<DownloadAction filename="immich-shared.zip" />
|
2023-07-01 00:50:47 -04:00
|
|
|
{/if}
|
|
|
|
|
{#if isOwned}
|
|
|
|
|
<RemoveFromSharedLink bind:sharedLink />
|
|
|
|
|
{/if}
|
|
|
|
|
</AssetSelectControlBar>
|
|
|
|
|
{:else}
|
2024-09-21 00:24:46 +02:00
|
|
|
<ControlAppBar onClose={() => goto(AppRoute.PHOTOS)} backIcon={mdiArrowLeft} showBackButton={false}>
|
2024-11-14 08:43:25 -06:00
|
|
|
{#snippet leading()}
|
2024-05-27 21:10:53 -05:00
|
|
|
<ImmichLogoSmallLink width={innerWidth} />
|
2024-11-14 08:43:25 -06:00
|
|
|
{/snippet}
|
2023-01-14 23:49:47 -06:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
{#snippet trailing()}
|
2023-07-01 00:50:47 -04:00
|
|
|
{#if sharedLink?.allowUpload}
|
2024-06-04 21:53:00 +02:00
|
|
|
<CircleIconButton
|
|
|
|
|
title={$t('add_photos')}
|
2024-11-14 08:43:25 -06:00
|
|
|
onclick={() => handleUploadAssets()}
|
2024-06-04 21:53:00 +02:00
|
|
|
icon={mdiFileImagePlusOutline}
|
|
|
|
|
/>
|
2023-07-01 00:50:47 -04:00
|
|
|
{/if}
|
2023-01-14 23:49:47 -06:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
{#if sharedLink?.allowDownload}
|
2024-11-14 08:43:25 -06:00
|
|
|
<CircleIconButton title={$t('download')} onclick={downloadAssets} icon={mdiFolderDownloadOutline} />
|
2023-07-01 00:50:47 -04:00
|
|
|
{/if}
|
2024-11-14 08:43:25 -06:00
|
|
|
{/snippet}
|
2023-07-01 00:50:47 -04:00
|
|
|
</ControlAppBar>
|
|
|
|
|
{/if}
|
2024-02-17 11:00:55 -06:00
|
|
|
<section class="my-[160px] mx-4" bind:clientHeight={viewport.height} bind:clientWidth={viewport.width}>
|
|
|
|
|
<GalleryViewer {assets} bind:selectedAssets {viewport} />
|
2023-07-01 00:50:47 -04:00
|
|
|
</section>
|
2023-01-14 23:49:47 -06:00
|
|
|
</section>
|