diff --git a/js/components/PlaylistWindow/TrackCell.js b/js/components/PlaylistWindow/TrackCell.js index 3752e07f..72954994 100644 --- a/js/components/PlaylistWindow/TrackCell.js +++ b/js/components/PlaylistWindow/TrackCell.js @@ -1,43 +1,77 @@ import React from "react"; import { connect } from "react-redux"; import classnames from "classnames"; +import { TRACK_HEIGHT } from "../../constants"; import { CLICKED_TRACK, CTRL_CLICKED_TRACK, SHIFT_CLICKED_TRACK, PLAY_TRACK } from "../../actionTypes"; +import { dragSelected } from "../../actionCreators"; import { getCurrentTrackId } from "../../selectors"; -const TrackCell = props => { - const { - skinPlaylistStyle, - selected, - current, - clickTrack, - playTrack, - children, - onMouseDown - } = props; - const style = { - backgroundColor: selected ? skinPlaylistStyle.selectedbg : null, - color: current ? skinPlaylistStyle.current : null - }; - return ( -
{ - onMouseDown(e); - clickTrack(e); - }} - onDoubleClick={playTrack} - onContextMenu={clickTrack} - > - {children} -
- ); -}; +class TrackCell extends React.Component { + constructor(props) { + super(props); + this._onMouseDown = this._onMouseDown.bind(this); + } + + _onMouseDown(e) { + if (e.shiftKey) { + this.props.shiftClick(e); + return; + } else if (e.metaKey || e.ctrlKey) { + this.props.ctrlClick(e); + return; + } + + if (!this.props.selected) { + this.props.click(e); + } + + const mouseStart = e.clientY; + let lastDiff = 0; + const handleMouseMove = ee => { + const proposedDiff = Math.floor((ee.clientY - mouseStart) / TRACK_HEIGHT); + if (proposedDiff !== lastDiff) { + const diffDiff = proposedDiff - lastDiff; + this.props.dragSelected(diffDiff); + lastDiff = proposedDiff; + } + }; + + window.addEventListener("mouseup", () => { + window.removeEventListener("mousemove", handleMouseMove); + }); + window.addEventListener("mousemove", handleMouseMove); + } + + render() { + const { + skinPlaylistStyle, + selected, + current, + children, + onDoubleClick + } = this.props; + const style = { + backgroundColor: selected ? skinPlaylistStyle.selectedbg : null, + color: current ? skinPlaylistStyle.current : null + }; + return ( +
e.preventDefault()} + onDoubleClick={onDoubleClick} + > + {children} +
+ ); + } +} const mapStateToProps = (state, ownProps) => { const { display: { skinPlaylistStyle }, playlist: { tracks } } = state; @@ -47,20 +81,17 @@ const mapStateToProps = (state, ownProps) => { }; const mapDispatchToProps = (dispatch, ownProps) => ({ - clickTrack: e => { - if (e.shiftKey) { - e.preventDefault(); - return dispatch({ type: SHIFT_CLICKED_TRACK, index: ownProps.index }); - } else if (e.metaKey) { - e.preventDefault(); - return dispatch({ type: CTRL_CLICKED_TRACK, index: ownProps.index }); - } else if (e.ctrlKey) { - e.preventDefault(); - return dispatch({ type: CTRL_CLICKED_TRACK, index: ownProps.index }); - } - return dispatch({ type: CLICKED_TRACK, index: ownProps.index }); + shiftClick: e => { + e.preventDefault(); + return dispatch({ type: SHIFT_CLICKED_TRACK, index: ownProps.index }); }, - playTrack: () => dispatch({ type: PLAY_TRACK, id: ownProps.id }) + ctrlClick: e => { + e.preventDefault(); + return dispatch({ type: CTRL_CLICKED_TRACK, index: ownProps.index }); + }, + click: () => dispatch({ type: CLICKED_TRACK, index: ownProps.index }), + dragSelected: offset => dispatch(dragSelected(offset)), + onDoubleClick: () => dispatch({ type: PLAY_TRACK, id: ownProps.id }) }); export default connect(mapStateToProps, mapDispatchToProps)(TrackCell); diff --git a/js/components/PlaylistWindow/TrackList.js b/js/components/PlaylistWindow/TrackList.js index cf0925bd..d3c70270 100644 --- a/js/components/PlaylistWindow/TrackList.js +++ b/js/components/PlaylistWindow/TrackList.js @@ -2,8 +2,6 @@ import React from "react"; import { connect } from "react-redux"; import { getTimeStr } from "../../utils"; -import { TRACK_HEIGHT } from "../../constants"; -import { dragSelected } from "../../actionCreators"; import { getVisibleTrackIds, getScrollOffset } from "../../selectors"; import TrackCell from "./TrackCell"; import TrackTitle from "./TrackTitle"; @@ -11,30 +9,11 @@ import TrackTitle from "./TrackTitle"; class TrackList extends React.Component { constructor(props) { super(props); - this._handleClick = this._handleClick.bind(this); - } - - _handleClick(e) { - const mouseStart = e.clientY; - let lastDiff = 0; - const handleMouseMove = ee => { - const proposedDiff = Math.floor((ee.clientY - mouseStart) / TRACK_HEIGHT); - if (proposedDiff !== lastDiff) { - const diffDiff = proposedDiff - lastDiff; - this.props.dragSelected(diffDiff); - lastDiff = proposedDiff; - } - }; - - window.addEventListener("mouseup", () => { - window.removeEventListener("mousemove", handleMouseMove); - }); - window.addEventListener("mousemove", handleMouseMove); } _renderTracks(format) { return this.props.trackIds.map((id, i) => ( - + {format(id, i)} )); @@ -58,14 +37,10 @@ class TrackList extends React.Component { } } -const mapDispatchToProps = { - dragSelected -}; - const mapStateToProps = state => ({ offset: getScrollOffset(state), trackIds: getVisibleTrackIds(state), tracks: state.playlist.tracks }); -export default connect(mapStateToProps, mapDispatchToProps)(TrackList); +export default connect(mapStateToProps)(TrackList);