Fix: allow multi-select drag and drop for moving multiple files at once
All checks were successful
Automated Container Build / build-and-push (push) Successful in 38s
All checks were successful
Automated Container Build / build-and-push (push) Successful in 38s
This commit is contained in:
parent
e9d1ef0ad6
commit
0bd42e5b47
1 changed files with 33 additions and 3 deletions
|
|
@ -899,6 +899,9 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
|
|||
}
|
||||
|
||||
function handleItemDragStart(e: React.DragEvent, path: string) {
|
||||
if (selectedFiles.has(path) && selectedFiles.size > 1) {
|
||||
e.dataTransfer.setData('application/json', JSON.stringify(Array.from(selectedFiles)));
|
||||
}
|
||||
e.dataTransfer.setData('text/plain', path);
|
||||
setDraggedFile(path);
|
||||
}
|
||||
|
|
@ -921,13 +924,40 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
|
|||
async function handleItemDrop(e: React.DragEvent, file: FileItem) {
|
||||
if (!file.is_dir) return;
|
||||
setDragOverFolder(null);
|
||||
const sourcePath = e.dataTransfer.getData('text/plain');
|
||||
if (!sourcePath || sourcePath === file.path) return;
|
||||
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setDraggedFile(null);
|
||||
|
||||
const jsonPaths = e.dataTransfer.getData('application/json');
|
||||
if (jsonPaths) {
|
||||
try {
|
||||
const paths = JSON.parse(jsonPaths);
|
||||
const fileNames = paths.map((p: string) => p.split('/').pop() || p);
|
||||
const res = await api.checkConflicts(file.path, fileNames);
|
||||
if (res.conflicts?.length) {
|
||||
setConflictState({ type: 'move', sourcePaths: paths, destPath: file.path, conflicts: res.conflicts });
|
||||
return;
|
||||
}
|
||||
await Promise.all(paths.map((p: string) => api.move(p, file.path)));
|
||||
loadFiles(undefined, true);
|
||||
setSelectedFiles(new Set());
|
||||
showToast(`Moved ${paths.length} items`);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const sourcePath = e.dataTransfer.getData('text/plain');
|
||||
if (!sourcePath || sourcePath === file.path) return;
|
||||
|
||||
try {
|
||||
const fileName = sourcePath.split('/').pop() || sourcePath;
|
||||
const res = await api.checkConflicts(file.path, [fileName]);
|
||||
if (res.conflicts?.length) {
|
||||
setConflictState({ type: 'move', sourcePaths: [sourcePath], destPath: file.path, conflicts: res.conflicts });
|
||||
return;
|
||||
}
|
||||
await api.move(sourcePath, file.path);
|
||||
loadFiles(undefined, true);
|
||||
showToast('Item moved');
|
||||
|
|
|
|||
Reference in a new issue