mirror of
https://github.com/get-drexa/drive.git
synced 2025-11-30 21:41:39 +00:00
fix: file/dir drag and drop
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ConvexError } from "convex/values"
|
||||
|
||||
export enum Code {
|
||||
export enum Code {
|
||||
Conflict = "Conflict",
|
||||
DirectoryExists = "DirectoryExists",
|
||||
DirectoryNotFound = "DirectoryNotFound",
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user