Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

Multiple items, to multiple collections

vishnukvmd6b7e729f29ea
diff --git a/web/apps/locker/src/components/CreateItemDialog.tsx b/web/apps/locker/src/components/CreateItemDialog.tsx
index defdbc2184..a05b33a0b7 100644
--- a/web/apps/locker/src/components/CreateItemDialog.tsx
+++ b/web/apps/locker/src/components/CreateItemDialog.tsx
@@ -1,6 +1,8 @@
import CheckRoundedIcon from "@mui/icons-material/CheckRounded";
import ChevronRightRoundedIcon from "@mui/icons-material/ChevronRightRounded";
import CloudUploadOutlinedIcon from "@mui/icons-material/CloudUploadOutlined";
+import ErrorOutlineRoundedIcon from "@mui/icons-material/ErrorOutlineRounded";
+import ScheduleRoundedIcon from "@mui/icons-material/ScheduleRounded";
import VisibilityIcon from "@mui/icons-material/Visibility";
import VisibilityOffIcon from "@mui/icons-material/VisibilityOff";
import {
@@ -41,6 +43,7 @@ import type { LockerCollection, LockerItemType } from "types";
import { isCollectionOwner, visibleLockerCollections } from "types";
type CreateOption = LockerItemType | "file";
+const MAX_PARALLEL_UPLOADS = 4;
interface LocalUser {
id: number;
@@ -100,9 +103,11 @@ interface CreateItemDialogProps {
collectionIDs: number[],
onProgress: (progress: LockerUploadProgress) => void,
) => Promise<void>;
+ onUploadItemComplete?: () => void;
+ onUploadsFinished?: (uploadedCount: number) => Promise<void>;
onCreateCollection?: (name: string) => Promise<number>;
defaultCollectionID?: number | null;
- initialFile?: File | null;
+ initialFiles?: File[];
editItem?: {
id: number;
type: LockerItemType;
@@ -117,9 +122,11 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({
collections,
onSave,
onUploadProgress,
+ onUploadItemComplete,
+ onUploadsFinished,
onCreateCollection,
defaultCollectionID,
- initialFile,
+ initialFiles,
editItem,
}) => {
const isEditMode = !!editItem;
@@ -145,9 +152,25 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({
editItem ? (editItem.data as Record<string, string>) : {},
);
const [showPassword, setShowPassword] = useState(false);
- const [selectedFile, setSelectedFile] = useState<File | null>(null);
- const [uploadProgress, setUploadProgress] =
- useState<LockerUploadProgress | null>(null);
+ const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
+ const [completedFileKeys, setCompletedFileKeys] = useState<Set<string>>(
+ () => new Set(),
+ );
+ const [failedFileKeys, setFailedFileKeys] = useState<Set<string>>(
+ () => new Set(),
+ );
+ const [uploadingFileKeys, setUploadingFileKeys] = useState<Set<string>>(
+ () => new Set(),
+ );
+ const [uploadProgressByFileKey, setUploadProgressByFileKey] = useState<
+ Record<string, LockerUploadProgress | null>
+ >({});
+ const [uploadCapByFileKey, setUploadCapByFileKey] = useState<
+ Record<string, number>
+ >({});
+ const [finalizingStartedAtByFileKey, setFinalizingStartedAtByFileKey] =
+ useState<Record<string, number>>({});
+ const [progressTick, setProgressTick] = useState(() => Date.now());
const fileInputRef = useRef<HTMLInputElement>(null);
const isFileMode = selectedOption === "file";
@@ -176,7 +199,9 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({
return;
}
- setSelectedOption(editItem?.type ?? (initialFile ? "file" : null));
+ setSelectedOption(
+ editItem?.type ?? (initialFiles?.length ? "file" : null),
+ );
setSelectedCollectionIDs(
isEditMode
? editCollectionID
@@ -191,14 +216,19 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({
);
setFormData(editItem ? (editItem.data as Record<string, string>) : {});
setShowPassword(false);
- setSelectedFile(initialFile ?? null);
+ setSelectedFiles(initialFiles ?? []);
+ setCompletedFileKeys(new Set());
+ setFailedFileKeys(new Set());
+ setUploadingFileKeys(new Set());
setError(null);
- setUploadProgress(null);
+ setUploadProgressByFileKey({});
+ setUploadCapByFileKey({});
+ setFinalizingStartedAtByFileKey({});
}, [
defaultCollectionID,
editCollectionID,
editItem,
- initialFile,
+ initialFiles,
isEditMode,
normalizeSelectedCollectionIDs,
open,
@@ -226,6 +256,18 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({
);
}, [displayCollections, isEditMode, open, selectedCollectionIDs]);
+ useEffect(() => {
+ if (!uploading) {
+ return;
+ }
+
+ const interval = window.setInterval(() => {
+ setProgressTick(Date.now());
+ }, 200);
+
+ return () => window.clearInterval(interval);
+ }, [uploading]);
+
const handleClose = useCallback(() => {
if (saving || uploading) {
return;
@@ -233,15 +275,26 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({
setError(null);
setShowPassword(false);
- setSelectedFile(null);
- setUploadProgress(null);
+ setSelectedFiles([]);
+ setCompletedFileKeys(new Set());
+ setFailedFileKeys(new Set());
+ setUploadingFileKeys(new Set());
+ setUploadProgressByFileKey({});
+ setUploadCapByFileKey({});
+ setFinalizingStartedAtByFileKey({});
onClose();
}, [onClose, saving, uploading]);
const handleSelectOption = useCallback((option: CreateOption) => {
setSelectedOption(option);
setFormData({});
- setSelectedFile(null);
+ setSelectedFiles([]);
+ setCompletedFileKeys(new Set());
+ setFailedFileKeys(new Set());
+ setUploadingFileKeys(new Set());
+ setUploadProgressByFileKey({});
+ setUploadCapByFileKey({});
+ setFinalizingStartedAtByFileKey({});
setError(null);
}, []);
@@ -252,9 +305,15 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({
const handleFileSelect = useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
- const file = event.target.files?.[0];
- if (file) {
- setSelectedFile(file);
+ const files = Array.from(event.target.files ?? []);
+ if (files.length > 0) {
+ setSelectedFiles(files);
+ setCompletedFileKeys(new Set());
+ setFailedFileKeys(new Set());
+ setUploadingFileKeys(new Set());
+ setUploadProgressByFileKey({});
+ setUploadCapByFileKey({});
+ setFinalizingStartedAtByFileKey({});
setError(null);
}
},
@@ -293,7 +352,7 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({
const handleUpload = useCallback(async () => {
if (
- !selectedFile ||
+ selectedFiles.length === 0 ||
selectedCollectionIDs.length === 0 ||
!onUploadProgress
) {
@@ -302,21 +361,117 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({
setUploading(true);
setError(null);
- setUploadProgress({ phase: "preparing" });
+ setCompletedFileKeys(new Set());
+ setFailedFileKeys(new Set());
+ setUploadingFileKeys(new Set());
+ setUploadProgressByFileKey({});
+ setUploadCapByFileKey({});
+ setFinalizingStartedAtByFileKey({});
+ let uploadedCount = 0;
try {
- await onUploadProgress(
- selectedFile,
- selectedCollectionIDs,
- setUploadProgress,
+ let nextIndex = 0;
+ const worker = async () => {
+ while (true) {
+ const file = selectedFiles[nextIndex];
+ nextIndex += 1;
+ if (!file) {
+ return;
+ }
+
+ const fileKey = uploadQueueItemKey(file);
+ setUploadingFileKeys((current) =>
+ new Set(current).add(fileKey),
+ );
+ setUploadCapByFileKey((current) => ({
+ ...current,
+ [fileKey]: 90 + Math.floor(Math.random() * 10),
+ }));
+ setUploadProgressByFileKey((current) => ({
+ ...current,
+ [fileKey]: { phase: "preparing" },
+ }));
+
+ try {
+ await onUploadProgress(
+ file,
+ selectedCollectionIDs,
+ (progress) => {
+ if (progress.phase === "finalizing") {
+ setFinalizingStartedAtByFileKey(
+ (current) =>
+ current[fileKey]
+ ? current
+ : {
+ ...current,
+ [fileKey]: Date.now(),
+ },
+ );
+ }
+ setUploadProgressByFileKey((current) => ({
+ ...current,
+ [fileKey]: progress,
+ }));
+ },
+ );
+ uploadedCount += 1;
+ setCompletedFileKeys((current) =>
+ new Set(current).add(fileKey),
+ );
+ setFailedFileKeys((current) => {
+ const next = new Set(current);
+ next.delete(fileKey);
+ return next;
+ });
+ onUploadItemComplete?.();
+ } catch (error) {
+ log.error("Failed to upload Locker file", error);
+ const formattedError = await formatLockerMutationError(
+ error,
+ "uploadFile",
+ );
+ setError((current) => current ?? formattedError);
+ setFailedFileKeys((current) =>
+ new Set(current).add(fileKey),
+ );
+ } finally {
+ setUploadingFileKeys((current) => {
+ const next = new Set(current);
+ next.delete(fileKey);
+ return next;
+ });
+ }
+ }
+ };
+
+ await Promise.all(
+ Array.from({
+ length: Math.min(
+ MAX_PARALLEL_UPLOADS,
+ selectedFiles.length,
+ ),
+ }).map(() => worker()),
);
- handleClose();
+
+ if (uploadedCount > 0) {
+ await onUploadsFinished?.(uploadedCount);
+ }
+ if (uploadedCount === selectedFiles.length) {
+ handleClose();
+ }
} catch (error) {
- log.error("Failed to upload Locker file", error);
+ log.error("Failed to upload Locker files", error);
setError(await formatLockerMutationError(error, "uploadFile"));
} finally {
setUploading(false);
}
- }, [handleClose, onUploadProgress, selectedCollectionIDs, selectedFile]);
+ }, [
+ handleClose,
+ onUploadProgress,
+ onUploadItemComplete,
+ onUploadsFinished,
+ selectedCollectionIDs,
+ selectedFiles,
+ ]);
const canSave =
selectedType !== null &&
@@ -326,7 +481,10 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({
);
const canUpload =
- isFileMode && selectedCollectionIDs.length > 0 && selectedFile !== null;
+ isFileMode &&
+ selectedCollectionIDs.length > 0 &&
+ selectedFiles.length > 0 &&
+ completedFileKeys.size + failedFileKeys.size !== selectedFiles.length;
return (
<Dialog
@@ -391,11 +549,12 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({
<input
ref={fileInputRef}
type="file"
+ multiple
hidden
onChange={handleFileSelect}
/>
- {!selectedFile ? (
+ {selectedFiles.length === 0 ? (
<ButtonBase
onClick={() => fileInputRef.current?.click()}
sx={(theme) => ({
@@ -426,96 +585,168 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({
</Typography>
</ButtonBase>
) : (
- <Stack
- sx={{
- borderRadius: "12px",
- backgroundColor: (theme) =>
- theme.vars.palette.fill.faint,
- overflow: "hidden",
- }}
- >
- <Stack
- direction="row"
- sx={{
- alignItems: "center",
- gap: 1.5,
- p: 2,
- }}
- >
- <Box
- sx={{
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- width: 48,
- height: 48,
- borderRadius: "12px",
- backgroundColor:
- lockerItemIconConfig(
- "file",
- selectedFile.name,
- ).backgroundColor,
- flexShrink: 0,
- }}
- >
- {lockerItemIcon("file", {
- fileName: selectedFile.name,
- size: 24,
- strokeWidth: 1.9,
- })}
- </Box>
- <Box sx={{ flex: 1, minWidth: 0 }}>
- <Typography variant="body" noWrap>
- {selectedFile.name}
- </Typography>
- <Typography
- variant="small"
- sx={{ color: "text.faint" }}
- >
- {formatFileSize(selectedFile.size)}
- </Typography>
- </Box>
- {!uploading && (
- <FocusVisibleButton
- size="small"
- color="secondary"
- onClick={() => {
- setSelectedFile(null);
- if (fileInputRef.current) {
- fileInputRef.current.value =
- "";
- }
+ <Stack sx={{ gap: 1.25 }}>
+ {selectedFiles.map((file) => {
+ const fileKey = uploadQueueItemKey(file);
+ const isDone =
+ completedFileKeys.has(fileKey);
+ const isFailed =
+ failedFileKeys.has(fileKey);
+ const isUploading =
+ uploadingFileKeys.has(fileKey);
+ const isQueued =
+ !isDone &&
+ !isFailed &&
+ !isUploading &&
+ uploading;
+ const uploadProgress =
+ uploadProgressByFileKey[fileKey];
+ const uploadCap =
+ uploadCapByFileKey[fileKey] ?? 95;
+ const finalizingStartedAt =
+ finalizingStartedAtByFileKey[fileKey];
+ return (
+ <Stack
+ key={fileKey}
+ sx={{
+ borderRadius: "12px",
+ backgroundColor: (theme) =>
+ theme.vars.palette.fill
+ .faint,
+ overflow: "hidden",
}}
>
- {t("change")}
- </FocusVisibleButton>
- )}
- </Stack>
- {uploading && (
- <LinearProgress
- variant={
- uploadProgress?.phase ===
- "uploading"
- ? "determinate"
- : "indeterminate"
- }
- value={
- uploadProgress?.phase ===
- "uploading"
- ? Math.min(
- 100,
- (uploadProgress.loaded /
- Math.max(
- uploadProgress.total,
- 1,
- )) *
- 100,
- )
- : undefined
- }
- sx={{ height: 4, borderRadius: 0 }}
- />
- )}
+ <Stack
+ direction="row"
+ sx={{
+ alignItems: "center",
+ gap: 1.5,
+ p: 2,
+ }}
+ >
+ <Box
+ sx={{
+ display: "flex",
+ alignItems: "center",
+ justifyContent:
+ "center",
+ width: 48,
+ height: 48,
+ borderRadius: "12px",
+ backgroundColor:
+ lockerItemIconConfig(
+ "file",
+ file.name,
+ ).backgroundColor,
+ flexShrink: 0,
+ }}
+ >
+ {lockerItemIcon("file", {
+ fileName: file.name,
+ size: 24,
+ strokeWidth: 1.9,
+ })}
+ </Box>
+ <Box
+ sx={{
+ flex: 1,
+ minWidth: 0,
+ }}
+ >
+ <Typography
+ variant="body"
+ noWrap
+ >
+ {file.name}
+ </Typography>
+ <Typography
+ variant="small"
+ sx={{
+ color: "text.faint",
+ }}
+ >
+ {formatFileSize(
+ file.size,
+ )}
+ </Typography>
+ </Box>
+ {isDone && (
+ <Box
+ sx={(theme) => ({
+ width: 24,
+ height: 24,
+ borderRadius: "50%",
+ display: "flex",
+ alignItems:
+ "center",
+ justifyContent:
+ "center",
+ backgroundColor:
+ theme.vars
+ .palette
+ .primary
+ .main,
+ color: theme.vars
+ .palette.primary
+ .contrastText,
+ flexShrink: 0,
+ })}
+ >
+ <CheckRoundedIcon
+ sx={{
+ fontSize: 16,
+ }}
+ />
+ </Box>
+ )}
+ {isFailed && (
+ <ErrorOutlineRoundedIcon
+ sx={{
+ color: "critical.main",
+ fontSize: 20,
+ flexShrink: 0,
+ }}
+ />
+ )}
+ {isQueued && (
+ <ScheduleRoundedIcon
+ sx={{
+ color: "text.muted",
+ fontSize: 20,
+ flexShrink: 0,
+ }}
+ />
+ )}
+ </Stack>
+ <Box sx={{ height: 4 }}>
+ <LinearProgress
+ variant="determinate"
+ value={
+ isUploading
+ ? uploadProgressValue(
+ uploadProgress,
+ uploadCap,
+ finalizingStartedAt,
+ progressTick,
+ )
+ : isDone
+ ? 100
+ : 0
+ }
+ sx={{
+ height: 4,
+ borderRadius: 0,
+ opacity:
+ isUploading ||
+ isDone
+ ? 1
+ : 0,
+ }}
+ />
+ </Box>
+ </Stack>
+ );
+ })}
</Stack>
)}
@@ -899,6 +1130,40 @@ const typeDisplayName = (type: LockerItemType): string => {
}
};
+const uploadQueueItemKey = (file: File) =>
+ `${file.name}:${file.size}:${file.lastModified}`;
+
+const uploadProgressValue = (
+ progress: LockerUploadProgress | null | undefined,
+ uploadCap: number,
+ finalizingStartedAt?: number,
+ now = Date.now(),
+) => {
+ if (!progress) {
+ return 0;
+ }
+
+ if (progress.phase === "uploading") {
+ return Math.min(
+ uploadCap,
+ (progress.loaded / Math.max(progress.total, 1)) * uploadCap,
+ );
+ }
+
+ if (progress.phase === "finalizing") {
+ const start = finalizingStartedAt ?? now;
+ const elapsed = Math.max(0, now - start);
+ const finalTarget = 99;
+ const easedFraction = 1 - Math.exp(-elapsed / 2200);
+ return Math.min(
+ finalTarget,
+ uploadCap + (finalTarget - uploadCap) * easedFraction,
+ );
+ }
+
+ return 0;
+};
+
const CollectionSelector: React.FC<{
collections: LockerCollection[];
selectedIDs: number[];
diff --git a/web/apps/locker/src/locales/en-US/translation.json b/web/apps/locker/src/locales/en-US/translation.json
index 9c0845ac97..550a25fbd7 100644
--- a/web/apps/locker/src/locales/en-US/translation.json
+++ b/web/apps/locker/src/locales/en-US/translation.json
@@ -100,6 +100,7 @@
"lastUpdated": "Last updated",
"createCollectionSuccess": "Collection created successfully",
"uploadComplete": "Item uploaded successfully",
+ "uploadMultipleComplete": "{{count, number}} items uploaded successfully",
"restore": "Restore",
"copyPassword": "Copy password",
"searchEverywhereEmpty": "Try searching for something else.",
diff --git a/web/apps/locker/src/locales/fr-FR/translation.json b/web/apps/locker/src/locales/fr-FR/translation.json
index 2f5c504625..ca39aba159 100644
--- a/web/apps/locker/src/locales/fr-FR/translation.json
+++ b/web/apps/locker/src/locales/fr-FR/translation.json
@@ -89,6 +89,7 @@
"hidePassword": "Masquer le mot de passe",
"lastUpdated": "Derniere mise a jour",
"uploadComplete": "Element televerse avec succes",
+ "uploadMultipleComplete": "{{count, number}} elements televerses avec succes",
"createCollectionSuccess": "Collection creee avec succes",
"home": "Accueil",
"security": "Securite",
diff --git a/web/apps/locker/src/locales/ja-JP/translation.json b/web/apps/locker/src/locales/ja-JP/translation.json
index c9d99ad3f0..70f2cfcdb2 100644
--- a/web/apps/locker/src/locales/ja-JP/translation.json
+++ b/web/apps/locker/src/locales/ja-JP/translation.json
@@ -92,6 +92,7 @@
"hidePassword": "パスワードを非表示",
"lastUpdated": "最終更新",
"uploadComplete": "アイテムが正常にアップロードされました",
+ "uploadMultipleComplete": "{{count, number}}件のアイテムを正常にアップロードしました",
"createCollectionSuccess": "コレクションが正常に作成されました",
"home": "ホーム",
"security": "セキュリティ",
diff --git a/web/apps/locker/src/pages/locker.tsx b/web/apps/locker/src/pages/locker.tsx
index b7534a36ee..c47bbdea62 100644
--- a/web/apps/locker/src/pages/locker.tsx
+++ b/web/apps/locker/src/pages/locker.tsx
@@ -82,6 +82,62 @@ type DragDataTransferItem = DataTransferItem & {
webkitGetAsEntry?: () => FileSystemEntry | null;
};
+type FileSystemFileEntry = FileSystemEntry & {
+ file: (
+ successCallback: (file: File) => void,
+ errorCallback?: (error: DOMException) => void,
+ ) => void;
+};
+
+interface FileSystemDirectoryReader {
+ readEntries: (
+ successCallback: (entries: FileSystemEntry[]) => void,
+ errorCallback?: (error: DOMException) => void,
+ ) => void;
+}
+
+type FileSystemDirectoryEntry = FileSystemEntry & {
+ createReader: () => FileSystemDirectoryReader;
+};
+
+const fileFromEntry = (entry: FileSystemFileEntry) =>
+ new Promise<File>((resolve, reject) => {
+ entry.file(resolve, reject);
+ });
+
+const readDirectoryEntries = (entry: FileSystemDirectoryEntry) =>
+ new Promise<FileSystemEntry[]>((resolve, reject) => {
+ const reader = entry.createReader();
+ const entries: FileSystemEntry[] = [];
+ const readBatch = () => {
+ reader.readEntries((batch) => {
+ if (batch.length === 0) {
+ resolve(entries);
+ return;
+ }
+ entries.push(...batch);
+ readBatch();
+ }, reject);
+ };
+ readBatch();
+ });
+
+const filesFromEntry = async (entry: FileSystemEntry): Promise<File[]> => {
+ if (entry.isFile) {
+ return [await fileFromEntry(entry as FileSystemFileEntry)];
+ }
+
+ if (entry.isDirectory) {
+ const entries = await readDirectoryEntries(
+ entry as FileSystemDirectoryEntry,
+ );
+ const files = await Promise.all(entries.map(filesFromEntry));
+ return files.flat();
+ }
+
+ return [];
+};
+
const hasPaidLockerAccess = (json: {
subscription?: { productID?: string; expiryTime?: number };
familyData?: { members?: unknown[] };
@@ -147,8 +203,8 @@ export const LockerPage: React.FC = () => {
// Create/Edit dialog state
const [createDialogOpen, setCreateDialogOpen] = useState(false);
- const [prefilledUploadFile, setPrefilledUploadFile] = useState<File | null>(
- null,
+ const [prefilledUploadFiles, setPrefilledUploadFiles] = useState<File[]>(
+ [],
);
const [editItem, setEditItem] = useState<{
id: number;
@@ -420,12 +476,26 @@ export const LockerPage: React.FC = () => {
) => {
if (!masterKey) throw new Error("No master key");
await uploadLockerFile(file, collectionIDs, masterKey, onProgress);
+ },
+ [masterKey],
+ );
+
+ const handleUploadsFinished = useCallback(
+ async (uploadedCount: number) => {
await refreshData();
- setToast(t("uploadComplete"));
+ setToast(
+ uploadedCount === 1
+ ? t("uploadComplete")
+ : t("uploadMultipleComplete", { count: uploadedCount }),
+ );
},
- [masterKey, refreshData],
+ [refreshData],
);
+ const handleUploadItemComplete = useCallback(() => {
+ void refreshData();
+ }, [refreshData]);
+
const handleUpdateItem = useCallback(
async (type: LockerItemType, data: Record<string, unknown>) => {
if (!masterKey || !editItem)
@@ -598,16 +668,16 @@ export const LockerPage: React.FC = () => {
const handleCreateDialogClose = useCallback(() => {
setCreateDialogOpen(false);
- setPrefilledUploadFile(null);
+ setPrefilledUploadFiles([]);
}, []);
- const openUploadDialogForFile = useCallback((file: File) => {
- setPrefilledUploadFile(file);
+ const openUploadDialogForFiles = useCallback((files: File[]) => {
+ setPrefilledUploadFiles(files);
setCreateDialogOpen(true);
}, []);
const openCreateDialog = useCallback(() => {
- setPrefilledUploadFile(null);
+ setPrefilledUploadFiles([]);
setCreateDialogOpen(true);
}, []);
@@ -652,40 +722,51 @@ export const LockerPage: React.FC = () => {
);
const handleDrop = useCallback(
- (event: React.DragEvent<HTMLElement>) => {
+ async (event: React.DragEvent<HTMLElement>) => {
event.preventDefault();
event.stopPropagation();
dragDepthRef.current = 0;
setIsDragActive(false);
- const droppedFiles = Array.from(event.dataTransfer.files);
const droppedItems = Array.from(
event.dataTransfer.items,
) as DragDataTransferItem[];
- const [droppedItem] = droppedItems;
-
- if (droppedFiles.length !== 1) {
- return;
- }
-
- if (
- droppedItems.length > 0 &&
- (droppedItems.length !== 1 ||
- droppedItem === undefined ||
- droppedItem.kind !== "file" ||
- droppedItem.webkitGetAsEntry()?.isDirectory)
- ) {
- return;
- }
+ const entryFiles = (
+ await Promise.all(
+ droppedItems
+ .filter((item) => item.kind === "file")
+ .map(async (item) => {
+ const entry = item.webkitGetAsEntry();
+ if (!entry) {
+ const file = item.getAsFile();
+ return file ? [file] : [];
+ }
+ return filesFromEntry(entry);
+ }),
+ )
+ ).flat();
+
+ const droppedFiles =
+ entryFiles.length > 0
+ ? entryFiles
+ : Array.from(event.dataTransfer.files);
+ const uniqueFiles = droppedFiles.filter(
+ (file, index, files) =>
+ files.findIndex(
+ (candidate) =>
+ candidate.name === file.name &&
+ candidate.size === file.size &&
+ candidate.lastModified === file.lastModified,
+ ) === index,
+ );
- const [file] = droppedFiles;
- if (!file) {
+ if (uniqueFiles.length === 0) {
return;
}
- openUploadDialogForFile(file);
+ openUploadDialogForFiles(uniqueFiles);
},
- [openUploadDialogForFile],
+ [openUploadDialogForFiles],
);
const handleRenameCollection = useCallback(
@@ -911,9 +992,11 @@ export const LockerPage: React.FC = () => {
collections={collections}
onSave={handleCreateItem}
onUploadProgress={handleUploadFileWithProgress}
+ onUploadItemComplete={handleUploadItemComplete}
+ onUploadsFinished={handleUploadsFinished}
onCreateCollection={handleCreateCollection}
defaultCollectionID={selectedCollectionID}
- initialFile={prefilledUploadFile}
+ initialFiles={prefilledUploadFiles}
/>
{/* Edit dialog */}