move multiple files at once

This commit is contained in:
2025-09-05 01:22:40 +02:00
parent 13e91fdfbf
commit 49c59cbaea
14 changed files with 224 additions and 112 deletions

View File

@@ -1,4 +1,4 @@
import { copyFile, moveFile } from '~/lib/api/warrens';
import { copyFile, moveFiles } from '~/lib/api/warrens';
import type { DirectoryEntry } from '~/shared/types';
export function joinPaths(path: string, ...other: string[]): string {
@@ -25,7 +25,11 @@ export function onDirectoryEntryDrop(
return async (e: DragEvent) => {
const warrenStore = useWarrenStore();
if (e.dataTransfer == null || warrenStore.current == null) {
if (
e.dataTransfer == null ||
warrenStore.current == null ||
warrenStore.current.dir == null
) {
return;
}
@@ -39,23 +43,29 @@ export function onDirectoryEntryDrop(
return;
}
const currentPath = joinPaths(warrenStore.current.path, fileName);
const draggedEntry = warrenStore.current.dir.entries.find(
(e) => e.name === fileName
);
if (draggedEntry == null) {
return;
}
const targetPaths = getTargetsFromSelection(
draggedEntry,
warrenStore.selection
).map((currentEntry) =>
joinPaths(warrenStore.current!.path, currentEntry.name)
);
let targetPath: string;
if (isParent) {
targetPath = joinPaths(
getParentPath(warrenStore.current.path),
fileName
);
targetPath = getParentPath(warrenStore.current.path);
} else {
targetPath = joinPaths(
warrenStore.current.path,
entry.name,
fileName
);
targetPath = joinPaths(warrenStore.current.path, entry.name);
}
await moveFile(warrenStore.current.warrenId, currentPath, targetPath);
await moveFiles(warrenStore.current.warrenId, targetPaths, targetPath);
};
}