From 0cbadee2e375ba71dc2c945dfce1e11724519c90 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Wed, 27 Jul 2016 23:51:42 -0700 Subject: [PATCH] Abstract file dragging --- js/DragTarget.jsx | 29 +++++++++++++++ js/MainWindow.jsx | 91 ++++++++++++++++++++++++++--------------------- js/main-window.js | 22 ------------ 3 files changed, 79 insertions(+), 63 deletions(-) create mode 100644 js/DragTarget.jsx diff --git a/js/DragTarget.jsx b/js/DragTarget.jsx new file mode 100644 index 00000000..62e5f4d7 --- /dev/null +++ b/js/DragTarget.jsx @@ -0,0 +1,29 @@ +import React from 'react'; + +class DragTarget extends React.Component { + constructor(props) { + super(props); + this.handleDrop = this.handleDrop.bind(this); + } + + supress(e) { + e.stopPropagation(); + e.preventDefault(); + } + + handleDrop(e) { + this.supress(e); + this.props.handleFiles(e.dataTransfer.files); + } + + render() { + return
; + {this.props.children} +
; + } +} + +module.exports = DragTarget; diff --git a/js/MainWindow.jsx b/js/MainWindow.jsx index d035da70..6e340fb1 100644 --- a/js/MainWindow.jsx +++ b/js/MainWindow.jsx @@ -6,6 +6,7 @@ import Actions from './Actions.jsx'; import Balance from './Balance.jsx'; import Close from './Close.jsx'; import ContextMenu from './ContextMenu.jsx'; +import DragTarget from './DragTarget.jsx'; import Eject from './Eject.jsx'; import Kbps from './Kbps.jsx'; import Khz from './Khz.jsx'; @@ -36,49 +37,57 @@ const MainWindow = (props) => { shade, closed }); - return
-
Loading...
-
- - -
- - -
-
-
-
-
-
-
-
+ + // TODO: Move this to an actionCreator + const handleDrop = (files) => { + props.winamp.loadFromFileReference(files[0]); + }; + + return +
+
Loading...
+
+ + +
+ +
-
-
-