2022-12-30 04:07:18 +02:00
|
|
|
<script lang="ts">
|
2023-07-01 00:50:47 -04:00
|
|
|
import { fade } from 'svelte/transition';
|
|
|
|
import ImmichLogo from './immich-logo.svelte';
|
2024-04-08 18:19:58 +02:00
|
|
|
import { page } from '$app/stores';
|
|
|
|
import { dragAndDropFilesStore } from '$lib/stores/drag-and-drop-files.store';
|
|
|
|
import { fileUploadHandler } from '$lib/utils/file-uploader';
|
2024-04-24 15:24:19 -04:00
|
|
|
import { isAlbumsRoute, isSharedLinkRoute } from '$lib/utils/navigation';
|
2024-06-24 15:50:01 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2024-04-08 18:19:58 +02:00
|
|
|
|
2024-04-24 15:24:19 -04:00
|
|
|
$: albumId = isAlbumsRoute($page.route?.id) ? $page.params.albumId : undefined;
|
|
|
|
$: isShare = isSharedLinkRoute($page.route?.id);
|
2023-02-27 04:23:43 +01:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
let dragStartTarget: EventTarget | null = null;
|
2023-03-04 16:09:55 -06:00
|
|
|
|
2024-04-08 18:19:58 +02:00
|
|
|
const onDragEnter = (e: DragEvent) => {
|
2024-06-08 11:57:46 +02:00
|
|
|
if (e.dataTransfer && e.dataTransfer.types.includes('Files')) {
|
2024-03-20 05:28:13 +01:00
|
|
|
dragStartTarget = e.target;
|
|
|
|
}
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
2022-12-30 04:07:18 +02:00
|
|
|
|
2024-04-08 18:19:58 +02:00
|
|
|
const onDragLeave = (e: DragEvent) => {
|
2023-07-01 00:50:47 -04:00
|
|
|
if (dragStartTarget === e.target) {
|
|
|
|
dragStartTarget = null;
|
|
|
|
}
|
2024-04-08 18:19:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const onDrop = async (e: DragEvent) => {
|
2023-07-01 00:50:47 -04:00
|
|
|
dragStartTarget = null;
|
2024-04-08 18:19:58 +02:00
|
|
|
await handleFiles(e.dataTransfer?.files);
|
|
|
|
};
|
|
|
|
|
|
|
|
const onPaste = ({ clipboardData }: ClipboardEvent) => handleFiles(clipboardData?.files);
|
|
|
|
|
|
|
|
const handleFiles = async (files?: FileList) => {
|
|
|
|
if (!files) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const filesArray: File[] = Array.from<File>(files);
|
|
|
|
if (isShare) {
|
|
|
|
dragAndDropFilesStore.set({ isDragging: true, files: filesArray });
|
|
|
|
} else {
|
|
|
|
await fileUploadHandler(filesArray, albumId);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<svelte:window on:paste={onPaste} />
|
|
|
|
|
|
|
|
<svelte:body
|
|
|
|
on:dragenter|stopPropagation|preventDefault={onDragEnter}
|
|
|
|
on:dragleave|stopPropagation|preventDefault={onDragLeave}
|
|
|
|
on:drop|stopPropagation|preventDefault={onDrop}
|
2023-02-27 04:23:43 +01:00
|
|
|
/>
|
|
|
|
|
|
|
|
{#if dragStartTarget}
|
2023-07-15 20:13:04 -05:00
|
|
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
2023-07-01 00:50:47 -04:00
|
|
|
<div
|
2023-07-18 13:19:39 -05:00
|
|
|
class="fixed inset-0 z-[1000] flex h-full w-full flex-col items-center justify-center bg-gray-100/90 text-immich-dark-gray dark:bg-immich-dark-bg/90 dark:text-immich-gray"
|
2023-07-01 00:50:47 -04:00
|
|
|
transition:fade={{ duration: 250 }}
|
|
|
|
on:dragover={(e) => {
|
|
|
|
// Prevent browser from opening the dropped file.
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
}}
|
|
|
|
>
|
2024-03-13 12:14:45 -05:00
|
|
|
<ImmichLogo noText class="m-16 w-48 animate-bounce" />
|
2024-06-24 15:50:01 +02:00
|
|
|
<div class="text-2xl">{$t('drop_files_to_upload')}</div>
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
2023-02-27 04:23:43 +01:00
|
|
|
{/if}
|