From a5c1b64900ae6b018a22ea54a95f463de01221b6 Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Mon, 23 Oct 2017 23:12:28 -0700 Subject: [PATCH] Fixes to document drag&drop --- frontend/components/Editor/Editor.js | 5 +- frontend/scenes/Document/Document.js | 151 ++++++++++----------------- 2 files changed, 57 insertions(+), 99 deletions(-) diff --git a/frontend/components/Editor/Editor.js b/frontend/components/Editor/Editor.js index b73d77388..7d158112a 100644 --- a/frontend/components/Editor/Editor.js +++ b/frontend/components/Editor/Editor.js @@ -83,6 +83,7 @@ type KeyData = { }; handleDrop = async (ev: SyntheticEvent) => { + if (this.props.readOnly) return; // check if this event was already handled by the Editor if (ev.isDefaultPrevented()) return; @@ -92,7 +93,9 @@ type KeyData = { const files = getDataTransferFiles(ev); for (const file of files) { - await this.insertImageFile(file); + if (file.type.startsWith('image/')) { + await this.insertImageFile(file); + } } }; diff --git a/frontend/scenes/Document/Document.js b/frontend/scenes/Document/Document.js index d290ad791..ed517e30d 100644 --- a/frontend/scenes/Document/Document.js +++ b/frontend/scenes/Document/Document.js @@ -27,7 +27,6 @@ import DocumentMenu from 'menus/DocumentMenu'; import SaveAction from './components/SaveAction'; import LoadingPlaceholder from 'components/LoadingPlaceholder'; import Editor from 'components/Editor'; -import DropToImport from 'components/DropToImport'; import LoadingIndicator from 'components/LoadingIndicator'; import Collaborators from 'components/Collaborators'; import CenteredContent from 'components/CenteredContent'; @@ -57,7 +56,6 @@ type Props = { @observable editCache: ?string; @observable newDocument: ?Document; - @observable isDragging = false; @observable isLoading = false; @observable isSaving = false; @observable notFound = false; @@ -198,14 +196,6 @@ type Props = { this.props.history.push(url); }; - onStartDragging = () => { - this.isDragging = true; - }; - - onStopDragging = () => { - this.isDragging = false; - }; - renderNotFound() { return ; } @@ -226,11 +216,6 @@ type Props = { return ( {isMoving && document && } - - {this.isDragging && - - Drop files here to import into Atlas. - } {titleText && } {this.isLoading && } {isFetching && @@ -239,73 +224,60 @@ type Props = { } {!isFetching && document && - - - - - - - {!isNew && - !this.isEditing && - } - - {this.isEditing - ? - : - Edit - } - - {this.isEditing && - - Discard - } - {!this.isEditing && - - - } - {!this.isEditing && } - - {!this.isEditing && - - + + + + + + {!isNew && + !this.isEditing && + } + + {this.isEditing + ? + : + Edit } - - - - - } + + {this.isEditing && + + Discard + } + {!this.isEditing && + + + } + {!this.isEditing && } + + {!this.isEditing && + + + } + + + + } ); } @@ -329,18 +301,6 @@ const HeaderAction = styled(Flex)` } `; -const DropHere = styled(Flex)` - pointer-events: none; - position: fixed; - top: 0; - left: ${layout.sidebarWidth}; - bottom: 0; - right: 0; - text-align: center; - background: rgba(255,255,255,.9); - z-index: 1; -`; - const Meta = styled(Flex)` align-items: flex-start; position: fixed; @@ -361,11 +321,6 @@ const LoadingState = styled(LoadingPlaceholder)` margin: 90px 0; `; -const StyledDropToImport = styled(DropToImport)` - display: flex; - flex: 1; -`; - export default withRouter( inject('ui', 'user', 'documents', 'collections')(DocumentScene) );