feat: check for name conflict on file/dir move

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2025-09-25 23:12:13 +00:00
parent 58775a25d9
commit 30027ae159
7 changed files with 126 additions and 30 deletions

View File

@@ -485,6 +485,7 @@ function FileItemRow({
return newDirectoryHandle(row.original.doc._id)
}
})
draggedItems.push(source)
setDragInfo({
source,

View File

@@ -1,5 +1,6 @@
import { api } from "@fileone/convex/_generated/api"
import type { Doc, Id } from "@fileone/convex/_generated/dataModel"
import * as Err from "@fileone/convex/model/error"
import type {
DirectoryHandle,
FileSystemHandle,
@@ -44,20 +45,31 @@ export function useFileDrop({
const { mutate: moveDroppedItems } = useMutation({
mutationFn: useContextMutation(api.filesystem.moveItems),
onSuccess: ({
items,
targetDirectory,
moved,
errors,
}: {
items: FileSystemHandle[]
targetDirectory: Doc<"directories">
moved: FileSystemHandle[]
errors: Err.ApplicationErrorData[]
}) => {
toast.success(
`${items.length} items moved to ${targetDirectory.name}`,
)
const conflictCount = errors.reduce((acc, error) => {
if (error.code === Err.Code.Conflict) {
return acc + 1
}
return acc
}, 0)
if (conflictCount > 0) {
toast.warning(
`${moved.length} items moved${conflictCount > 0 ? `, ${conflictCount} conflicts` : ""}`,
)
} else {
toast.success(`${moved.length} items moved!`)
}
},
})
const handleDrop = (_e: React.DragEvent) => {
const dragInfo = store.get(dragInfoAtom)
console.log("dragInfo", dragInfo)
if (dragInfo && item) {
moveDroppedItems({
targetDirectory: item,

View File

@@ -8,6 +8,10 @@ const ERROR_MESSAGE = {
[ErrorCode.DirectoryExists]: "Directory already exists",
[ErrorCode.FileExists]: "File already exists",
[ErrorCode.Internal]: "Internal application error",
[ErrorCode.Conflict]: "Conflict",
[ErrorCode.DirectoryNotFound]: "Directory not found",
[ErrorCode.FileNotFound]: "File not found",
[ErrorCode.Unauthenticated]: "Unauthenticated",
} as const
export function formatError(error: unknown): string {