|
|
@ -4,8 +4,6 @@ import { buildMultiSelectedItemProfiles, getEventTarget } from '../utils/getEven |
|
|
|
import { extractParentFromKey } from '@remix-ui/helper' |
|
|
|
import { extractParentFromKey } from '@remix-ui/helper' |
|
|
|
import { FileSystemContext } from '../contexts' |
|
|
|
import { FileSystemContext } from '../contexts' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const FlatTreeDrop = (props: FlatTreeDropProps) => { |
|
|
|
export const FlatTreeDrop = (props: FlatTreeDropProps) => { |
|
|
|
|
|
|
|
|
|
|
|
const { getFlatTreeItem, dragSource, handleClickFolder, expandPath } = props |
|
|
|
const { getFlatTreeItem, dragSource, handleClickFolder, expandPath } = props |
|
|
@ -13,9 +11,6 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { |
|
|
|
const [timer, setTimer] = useState<NodeJS.Timeout>() |
|
|
|
const [timer, setTimer] = useState<NodeJS.Timeout>() |
|
|
|
// folder to open
|
|
|
|
// folder to open
|
|
|
|
const [folderToOpen, setFolderToOpen] = useState<string>() |
|
|
|
const [folderToOpen, setFolderToOpen] = useState<string>() |
|
|
|
const globalFEContext = useContext(FileSystemContext) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [selectedItems, setSelectedItems] = useState<DragStructure[]>([]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const onDragOver = async (e: SyntheticEvent) => { |
|
|
|
const onDragOver = async (e: SyntheticEvent) => { |
|
|
|
e.preventDefault() |
|
|
|
e.preventDefault() |
|
|
@ -66,23 +61,12 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { |
|
|
|
props.setFilesSelected(filePaths) |
|
|
|
props.setFilesSelected(filePaths) |
|
|
|
|
|
|
|
|
|
|
|
if (dragDestination.isDirectory) { |
|
|
|
if (dragDestination.isDirectory) { |
|
|
|
if (dragSource.isDirectory) { |
|
|
|
await props.warnMovingItems(filePaths, dragDestination.path) |
|
|
|
await props.warnMovingItems(filePaths, dragDestination.path) |
|
|
|
await moveItemsSilently(props.selectedItems, dragDestination.path) |
|
|
|
await moveFoldersSilently(props.selectedItems, dragDestination.path) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
await props.warnMovingItems(filePaths, dragDestination.path) |
|
|
|
|
|
|
|
await moveFilesSilently(props.selectedItems, dragDestination.path) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const path = extractParentFromKey(dragDestination.path) || '/' |
|
|
|
const path = extractParentFromKey(dragDestination.path) || '/' |
|
|
|
|
|
|
|
await props.warnMovingItems(filePaths, path) |
|
|
|
if (dragSource.isDirectory) { |
|
|
|
await moveItemsSilently(props.selectedItems, path) |
|
|
|
await props.warnMovingItems(filePaths, path) |
|
|
|
|
|
|
|
await moveFoldersSilently(props.selectedItems, path) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
await props.warnMovingItems(filePaths, path) |
|
|
|
|
|
|
|
await moveFilesSilently(props.selectedItems, path) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -92,33 +76,18 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { |
|
|
|
* @param dragSource source FileExplorer item being dragged. |
|
|
|
* @param dragSource source FileExplorer item being dragged. |
|
|
|
* @returns Promise<void> |
|
|
|
* @returns Promise<void> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
const moveFilesSilently = async (items: DragStructure[], targetPath: string) => { |
|
|
|
const moveItemsSilently = async (items: DragStructure[], targetPath: string) => { |
|
|
|
const promises = items.filter(item => item.path !== targetPath) |
|
|
|
const promises = items.filter(item => item.path !== targetPath) |
|
|
|
.map(async (item) => { |
|
|
|
.map(async (item) => { |
|
|
|
if (item.type === 'file') { |
|
|
|
if (item.type === 'file') { |
|
|
|
await props.moveFileSilently(targetPath, item.path) |
|
|
|
await props.moveFileSilently(targetPath, item.path) |
|
|
|
} |
|
|
|
} else if (item.type === 'folder') { |
|
|
|
}) |
|
|
|
|
|
|
|
await Promise.all(promises) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Moves items silently without showing a confirmation dialog. |
|
|
|
|
|
|
|
* @param items MultiSelected items built into a DragStructure profile |
|
|
|
|
|
|
|
* @param dragSource source FileExplorer item being dragged. |
|
|
|
|
|
|
|
* @returns Promise<void> |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
const moveFoldersSilently = async (items: DragStructure[], targetPath: string) => { |
|
|
|
|
|
|
|
const promises = items.filter(item => item.path !== targetPath) |
|
|
|
|
|
|
|
.map(async (item) => { |
|
|
|
|
|
|
|
if (item.type === 'folder') { |
|
|
|
|
|
|
|
await props.moveFolderSilently(targetPath, item.path) |
|
|
|
await props.moveFolderSilently(targetPath, item.path) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
await Promise.all(promises) |
|
|
|
await Promise.all(promises) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (<div |
|
|
|
return (<div |
|
|
|
onDrop={onDrop} onDragOver={onDragOver} |
|
|
|
onDrop={onDrop} onDragOver={onDragOver} |
|
|
|
className="d-flex h-100" |
|
|
|
className="d-flex h-100" |
|
|
|