fix: file drop for file item row in dir table

This commit is contained in:
2025-12-15 22:45:32 +00:00
parent 06373404b2
commit 24af10c094
2 changed files with 17 additions and 5 deletions

View File

@@ -298,7 +298,8 @@ function FileItemRow({
const setFileDragInfo = useSetAtom(fileDragInfoAtom)
const { isDraggedOver, dropHandlers } = useFileDrop({
destDir: row.original,
enabled: row.original.kind === "directory",
destDir: row.original.kind === "directory" ? row.original : undefined,
dragInfoAtom: fileDragInfoAtom,
})
@@ -306,8 +307,15 @@ function FileItemRow({
let draggedItems: DirectoryItem[]
// drag all selections, but only if the currently dragged row is also selected
if (row.getIsSelected()) {
draggedItems = [...table.getSelectedRowModel().rows]
if (!draggedItems.some((item) => item.id === row.original.id)) {
draggedItems = []
let currentRowFound = false
for (const { original: item } of table.getSelectedRowModel().rows) {
draggedItems.push(item)
if (item.id === row.original.id) {
currentRowFound = true
}
}
if (!currentRowFound) {
draggedItems.push(row.original)
}
} else {

View File

@@ -15,8 +15,9 @@ export interface FileDragInfo {
}
export interface UseFileDropOptions {
destDir: DirectoryInfo | string
destDir?: DirectoryInfo | string
dragInfoAtom: PrimitiveAtom<FileDragInfo | null>
enabled?: boolean
}
export interface UseFileDropReturn {
@@ -31,6 +32,7 @@ export interface UseFileDropReturn {
export function useFileDrop({
destDir,
dragInfoAtom,
enabled,
}: UseFileDropOptions): UseFileDropReturn {
const [isDraggedOver, setIsDraggedOver] = useState(false)
const setDragInfo = useSetAtom(dragInfoAtom)
@@ -50,9 +52,11 @@ export function useFileDrop({
},
})
const dirId = typeof destDir === "string" ? destDir : destDir.id
const dirId = typeof destDir === "string" ? destDir : destDir?.id
const handleDrop = (_e: React.DragEvent) => {
if (!enabled || !destDir || !dirId) return
const dragInfo = store.get(dragInfoAtom)
if (dragInfo) {
const items = dragInfo.items.filter((item) => item.id !== dirId)