mirror of
https://github.com/get-drexa/drive.git
synced 2026-02-02 14:51:18 +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 setFileDragInfo = useSetAtom(fileDragInfoAtom)
|
||||||
|
|
||||||
const { isDraggedOver, dropHandlers } = useFileDrop({
|
const { isDraggedOver, dropHandlers } = useFileDrop({
|
||||||
destDir: row.original,
|
enabled: row.original.kind === "directory",
|
||||||
|
destDir: row.original.kind === "directory" ? row.original : undefined,
|
||||||
dragInfoAtom: fileDragInfoAtom,
|
dragInfoAtom: fileDragInfoAtom,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -306,8 +307,15 @@ function FileItemRow({
|
|||||||
let draggedItems: DirectoryItem[]
|
let draggedItems: DirectoryItem[]
|
||||||
// drag all selections, but only if the currently dragged row is also selected
|
// drag all selections, but only if the currently dragged row is also selected
|
||||||
if (row.getIsSelected()) {
|
if (row.getIsSelected()) {
|
||||||
draggedItems = [...table.getSelectedRowModel().rows]
|
draggedItems = []
|
||||||
if (!draggedItems.some((item) => item.id === row.original.id)) {
|
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)
|
draggedItems.push(row.original)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ export interface FileDragInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface UseFileDropOptions {
|
export interface UseFileDropOptions {
|
||||||
destDir: DirectoryInfo | string
|
destDir?: DirectoryInfo | string
|
||||||
dragInfoAtom: PrimitiveAtom<FileDragInfo | null>
|
dragInfoAtom: PrimitiveAtom<FileDragInfo | null>
|
||||||
|
enabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UseFileDropReturn {
|
export interface UseFileDropReturn {
|
||||||
@@ -31,6 +32,7 @@ export interface UseFileDropReturn {
|
|||||||
export function useFileDrop({
|
export function useFileDrop({
|
||||||
destDir,
|
destDir,
|
||||||
dragInfoAtom,
|
dragInfoAtom,
|
||||||
|
enabled,
|
||||||
}: UseFileDropOptions): UseFileDropReturn {
|
}: UseFileDropOptions): UseFileDropReturn {
|
||||||
const [isDraggedOver, setIsDraggedOver] = useState(false)
|
const [isDraggedOver, setIsDraggedOver] = useState(false)
|
||||||
const setDragInfo = useSetAtom(dragInfoAtom)
|
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) => {
|
const handleDrop = (_e: React.DragEvent) => {
|
||||||
|
if (!enabled || !destDir || !dirId) return
|
||||||
|
|
||||||
const dragInfo = store.get(dragInfoAtom)
|
const dragInfo = store.get(dragInfoAtom)
|
||||||
if (dragInfo) {
|
if (dragInfo) {
|
||||||
const items = dragInfo.items.filter((item) => item.id !== dirId)
|
const items = dragInfo.items.filter((item) => item.id !== dirId)
|
||||||
|
|||||||
Reference in New Issue
Block a user