directory back up (parent) button + drag entry into parent to move

This commit is contained in:
2025-07-30 17:25:10 +02:00
parent 2c834eb42b
commit 3b141cc7cd
18 changed files with 243 additions and 95 deletions

49
frontend/utils/files.ts Normal file
View File

@@ -0,0 +1,49 @@
import { moveFile } from '~/lib/api/warrens';
import type { DirectoryEntry } from '~/shared/types';
export function getParentPath(path: string): string {
const sliceEnd = Math.max(1, path.lastIndexOf('/'));
return path.slice(0, sliceEnd);
}
export function onDirectoryEntryDrop(
entry: DirectoryEntry,
isParent: boolean = false
): (e: DragEvent) => void {
return async (e: DragEvent) => {
const warrenStore = useWarrenStore();
if (e.dataTransfer == null || warrenStore.current == null) {
return;
}
if (entry.fileType !== 'directory') {
return;
}
const fileName = e.dataTransfer.getData('application/warren');
if (entry.name === fileName) {
return;
}
let targetPath: string;
if (isParent) {
targetPath = getParentPath(warrenStore.current.path);
} else {
targetPath = warrenStore.current.path;
if (!targetPath.endsWith('/')) {
targetPath += '/';
}
targetPath += entry.name;
}
await moveFile(
warrenStore.current.warrenId,
warrenStore.current.path,
fileName,
targetPath
);
};
}