Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag-Drop feature #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions src/views/Explorer/FilesView/FileComponent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react";
import ReactDOM from "react-dom";
import {
Button,
Card,
Expand All @@ -7,6 +8,10 @@ import {
DropdownItem,
DropdownMenu,
DropdownToggle,
Modal,
ModalHeader,
ModalBody,
ModalFooter,
UncontrolledButtonDropdown
} from "reactstrap";

Expand All @@ -23,7 +28,8 @@ import ErrorBoundary from "../../../ErrorHandling/ErrorBoundary";

async function performCopyMoveOperation(params) {
const {srcRemoteName, srcRemotePath, destRemoteName, destRemotePath, Name, IsDir, dropEffect, updateHandler} = params;
if (dropEffect === "move") { /*Default operation without holding alt is copy, named as move in react-dnd*/

if (dropEffect === "copy") { /*Default operation without holding alt is copy, named as move in react-dnd*/
// if (component.props.canCopy) {
await performCopyFile(srcRemoteName, srcRemotePath, destRemoteName, destRemotePath, Name, IsDir);
updateHandler();
Expand All @@ -36,7 +42,7 @@ async function performCopyMoveOperation(params) {
// toast.error("This remote does not support copying");
// }

} else {
} else if (dropEffect === "move") {
// if (component.props.canMove) {
await performMoveFile(srcRemoteName, srcRemotePath, destRemoteName, destRemotePath, Name, IsDir);
updateHandler();
Expand All @@ -52,13 +58,48 @@ async function performCopyMoveOperation(params) {
}
}

let modalbox = true;
let operation = "";

const modalClose = () => {
const modalNode = document.getElementById("mainModalElement");
ReactDOM.unmountComponentAtNode(modalNode);
ReactDOM.render(emptyElement, document.getElementById("modalElement"));
}

const modalMove = () => {
const modalNode = document.getElementById("mainModalElement");
ReactDOM.unmountComponentAtNode(modalNode);
operation = "move";
ReactDOM.render(emptyElement, document.getElementById("modalElement"));
}

const modalCopy = () => {
const modalNode = document.getElementById("mainModalElement");
ReactDOM.unmountComponentAtNode(modalNode);
operation = "copy";
ReactDOM.render(emptyElement, document.getElementById("modalElement"));
}

let emptyElement = (<div></div>);
let modalElement = (
<Modal id="mainModalElement" isOpen={modalbox} toggle={modalClose}>
<ModalHeader>Confirm Operation</ModalHeader>
<ModalBody> Confirm operation: Move or Copy </ModalBody>
<ModalFooter>
<Button color="primary" onClick={modalMove}>Move</Button>{' '}
<Button color="primary" onClick={modalCopy}>Copy</Button>
</ModalFooter>
</Modal>
);

const fileComponentSource = {
canDrag(props) {

// You can disallow drag based on props
return true;
},

beginDrag(props) {
// console.log("props", props, props.remoteName);
const {Name, Path, IsDir} = props.item;
Expand All @@ -70,6 +111,8 @@ const fileComponentSource = {
endDrag(props, monitor, component) {
// console.log("EndDrag", monitor.getDropResult());
console.log(props, "Component:", component);
ReactDOM.render(modalElement, document.getElementById("modalElement"));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that here we'll have to wait for the component to be rendered and processed completely and only after that getting the value of operation will be possible.
As of now, before the element is rendered completely, the code runs to console.log(operation); and then to try block ignoring the modalElement.......can Async-Await deal with this problem?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way to go about it could be to delay the calling of performCopyMoveOperation() till the modal opens and closes.

console.log(operation);
try {
if (monitor.getDropResult() && component) {
performCopyMoveOperation(monitor.getDropResult());
Expand Down Expand Up @@ -214,6 +257,7 @@ class FileComponent extends React.Component {
clickHandler(e, item)
}
}

render() {
const {containerID, inViewport, item, loadImages, clickHandler, downloadHandle, linkShareHandle, deleteHandle, connectDragSource, gridMode, itemIdx /*isDragging, remoteName*/} = this.props;

Expand Down Expand Up @@ -257,8 +301,12 @@ class FileComponent extends React.Component {
</tr>
)
}

return <ErrorBoundary>
{element}
<button onClick={this.modalOpen}>Open Modal</button>
<div id="modalElement">
</div>
</ErrorBoundary>;
}
}
Expand Down