diff --git a/js/components/DropTarget.js b/js/components/DropTarget.js new file mode 100644 index 00000000..51da601c --- /dev/null +++ b/js/components/DropTarget.js @@ -0,0 +1,39 @@ +import React from "react"; +import { connect } from "react-redux"; + +import { loadFileFromReference } from "../actionCreators"; + +export class DropTarget extends React.Component { + constructor(props) { + super(props); + this.handleDrop = this.handleDrop.bind(this); + } + + supress(e) { + e.stopPropagation(); + e.preventDefault(); + } + + handleDrop(e) { + this.supress(e); + const { files } = e.dataTransfer; + if (files[0]) { + this.props.loadFileFromReference(files[0]); + } + } + + render() { + // eslint-disable-next-line no-shadow, no-unused-vars + const { loadFileFromReference, ...passThroughProps } = this.props; + return ( +
+ ); + } +} + +export default connect(null, { loadFileFromReference })(DropTarget); diff --git a/js/components/MainWindow/index.js b/js/components/MainWindow/index.js index 7adcaf5f..e8fac09a 100644 --- a/js/components/MainWindow/index.js +++ b/js/components/MainWindow/index.js @@ -4,6 +4,7 @@ import classnames from "classnames"; import { WINDOWS } from "../../constants"; +import DropTarget from "../DropTarget"; import MiniTime from "../MiniTime"; import ActionButtons from "./ActionButtons"; @@ -28,34 +29,18 @@ import MainVolume from "./MainVolume"; import { SET_FOCUSED_WINDOW } from "../../actionTypes"; -import { loadFileFromReference } from "../../actionCreators"; - import "../../../css/main-window.css"; export class MainWindow extends React.Component { constructor(props) { super(props); this.handleClick = this.handleClick.bind(this); - this.handleDrop = this.handleDrop.bind(this); } handleClick() { this.props.setFocus(); } - supress(e) { - e.stopPropagation(); - e.preventDefault(); - } - - handleDrop(e) { - this.supress(e); - const { files } = e.dataTransfer; - if (files[0]) { - this.props.loadFileFromReference(files[0]); - } - } - render() { const { focused, @@ -82,13 +67,10 @@ export class MainWindow extends React.Component { }); return ( -