fix: file/dir drag and drop

This commit is contained in:
2025-09-26 22:20:30 +00:00
parent 1c89f7c60b
commit 56fb2aa24f
6 changed files with 71 additions and 35 deletions

View File

@@ -194,8 +194,6 @@ export async function move(
),
)
console.log(sourceDirectories)
const errors: Err.ApplicationErrorData[] = []
const okDirectories: DirectoryHandle[] = []
conflictCheckResults.forEach((result, i) => {
@@ -215,11 +213,22 @@ export async function move(
}
})
const results = await Promise.allSettled(
okDirectories.map((handle) =>
ctx.db.patch(handle.id, { parentId: targetDirectory.id }),
),
)
const ignoredHandles = new Set<DirectoryHandle>()
const promises: Promise<void>[] = []
for (const handle of okDirectories) {
if (handle.id === targetDirectory.id) {
// if the directory that needs to be moved is the same as the dest directory
// it is silently ignored
ignoredHandles.add(handle)
} else {
promises.push(
ctx.db.patch(handle.id, { parentId: targetDirectory.id }),
)
}
}
const results = await Promise.allSettled(promises)
for (const updateResult of results) {
if (updateResult.status === "rejected") {
@@ -227,7 +236,10 @@ export async function move(
}
}
return { moved: okDirectories, errors }
return {
moved: okDirectories.filter((handle) => !ignoredHandles.has(handle)),
errors,
}
}
export async function moveToTrashRecursive(

View File

@@ -1,6 +1,6 @@
import { ConvexError } from "convex/values"
export enum Code {
export enum Code {
Conflict = "Conflict",
DirectoryExists = "DirectoryExists",
DirectoryNotFound = "DirectoryNotFound",

View File

@@ -35,3 +35,10 @@ export function newDirectoryHandle(id: Id<"directories">): DirectoryHandle {
export function newFileHandle(id: Id<"files">): FileHandle {
return { kind: "file", id }
}
export function isSameHandle(
handle1: FileSystemHandle,
handle2: FileSystemHandle,
): boolean {
return handle1.kind === handle2.kind && handle1.id === handle2.id
}