From ec62b37e238568564c98f05ef67d09b6a75702b6 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Sun, 19 Nov 2017 11:42:11 -0800 Subject: [PATCH] Abstract dropping files. Add to playlist --- js/components/DropTarget.js | 39 +++++++++++++++++++ js/components/MainWindow/index.js | 27 ++----------- .../__snapshots__/index.test.js.snap | 4 ++ js/components/PlaylistWindow/index.js | 5 ++- 4 files changed, 50 insertions(+), 25 deletions(-) create mode 100644 js/components/DropTarget.js 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 ( -
@@ -132,7 +114,7 @@ export class MainWindow extends React.Component { href="https://github.com/captbaritone/winamp2-js" title="About" /> -
+ ); } } @@ -147,7 +129,6 @@ const mapStateToProps = state => { }; const mapDispatchToProps = { - setFocus: () => ({ type: SET_FOCUSED_WINDOW, window: WINDOWS.MAIN }), - loadFileFromReference + setFocus: () => ({ type: SET_FOCUSED_WINDOW, window: WINDOWS.MAIN }) }; export default connect(mapStateToProps, mapDispatchToProps)(MainWindow); diff --git a/js/components/PlaylistWindow/__snapshots__/index.test.js.snap b/js/components/PlaylistWindow/__snapshots__/index.test.js.snap index 5f8169e2..9606180c 100644 --- a/js/components/PlaylistWindow/__snapshots__/index.test.js.snap +++ b/js/components/PlaylistWindow/__snapshots__/index.test.js.snap @@ -4,6 +4,9 @@ exports[`PlaylistWindow renders to snapshot 1`] = `
{ const tracks = trackOrder.slice(offset, offset + numberOfVisibleTracks); return ( -
{
-
+ ); };