mirror of
https://github.com/get-drexa/drive.git
synced 2026-02-02 11:51:17 +00:00
fix: file drop for file item row in dir table
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user