feat(dnd): added support for drag and drop

This commit is contained in:
Ritesh Kumar committed 2020-01-05 17:43:36 +05:30
1 parent 16cf173411
commit ed535eeee1
7 files changed
+55 -1493

No files matched your search

+23 -3
View File
@@ -19,6 +19,7 @@ import copy from "clipboard-copy";
import { getWorker, Wrapper } from "@utils/workerWrapper";
import Npm from "@assets/svgs/Npm";
import { supportedLanguages } from "@utils/prettier";
import { useDropzone } from "react-dropzone";
export interface EditorPanelProps {
editable?: boolean;
@@ -132,7 +133,8 @@ export default function({
[showSettingsDialogue]
);
const onFilePicked = useCallback((files, close) => {
const onFilePicked = useCallback((files, close = () => {}) => {
if (!(files && files.length)) return;
const file = files[0];
const reader = new FileReader();
reader.readAsText(file, "utf-8");
@@ -143,6 +145,16 @@ export default function({
};
}, []);
const { getRootProps } = useDropzone({
onDrop: files => onFilePicked(files),
disabled: !editable,
accept: acceptFiles,
onDropRejected: () =>
toaster.danger("This file type is not supported.", {
id
})
});
const copyValue = useCallback(() => {
copy(value);
toaster.success("Copied to clipboard.", {
@@ -310,7 +322,15 @@ export default function({
)}
</Pane>
<Pane display="flex" flexDirection="column" flex={1} overflow="hidden">
<div
style={{
display: "flex",
flexDirection: "column",
flex: 1,
overflow: "hidden"
}}
{...getRootProps()}
>
{topNotifications &&
topNotifications({
isSettingsOpen: showSettingsDialogue,
@@ -327,7 +347,7 @@ export default function({
}}
innerRef={editorRef}
/>
</Pane>
</div>
{IN_BROWSER && showPreview && previewElement && (
<Pane display="flex" flex={1} flexDirection="column" overflow="hidden">