import React from "react";
import { connect } from "react-redux";
import classnames from "classnames";
import { WINDOWS, TRACK_HEIGHT } from "../../constants";
import { TOGGLE_PLAYLIST_WINDOW, SET_FOCUSED_WINDOW } from "../../actionTypes";
import {
toggleVisualizerStyle,
scrollUpFourTracks,
scrollDownFourTracks,
loadFilesFromReferences,
togglePlaylistShadeMode,
scrollVolume
} from "../../actionCreators";
import { getScrollOffset, getPlaylistWindowPixelSize } from "../../selectors";
import { clamp } from "../../utils";
import DropTarget from "../DropTarget";
import PlaylistShade from "./PlaylistShade";
import AddMenu from "./AddMenu";
import RemoveMenu from "./RemoveMenu";
import SelectionMenu from "./SelectionMenu";
import MiscMenu from "./MiscMenu";
import ListMenu from "./ListMenu";
import PlaylistResizeTarget from "./PlaylistResizeTarget";
import PlaylistActionArea from "./PlaylistActionArea";
import TrackList from "./TrackList";
import ScrollBar from "./ScrollBar";
import "../../../css/playlist-window.css";
class PlaylistWindow extends React.Component {
constructor(props) {
super(props);
this._handleDrop = this._handleDrop.bind(this);
}
_handleDrop(e, targetCoords) {
const top = e.clientY - targetCoords.y;
const atIndex = clamp(
this.props.offset + Math.round((top - 23) / TRACK_HEIGHT),
0,
this.props.maxTrackIndex + 1
);
this.props.loadFilesFromReferences(e, atIndex);
}
render() {
const {
skinPlaylistStyle,
focusPlaylist,
focused,
playlistSize,
playlistWindowPixelSize,
playlistShade,
close,
toggleShade
} = this.props;
if (playlistShade) {
return ;
}
const style = {
color: skinPlaylistStyle.normal,
backgroundColor: skinPlaylistStyle.normalbg,
fontFamily: `${skinPlaylistStyle.font}, Arial, sans-serif`,
height: `${playlistWindowPixelSize.height}px`,
width: `${playlistWindowPixelSize.width}px`
};
const classes = classnames("window", "draggable", {
selected: focused === WINDOWS.PLAYLIST,
wide: playlistSize[0] > 2
});
const showSpacers = playlistSize[0] % 2 === 0;
return (
{showSpacers && (
)}
{showSpacers && (
)}
);
}
}
const mapDispatchToProps = {
focusPlaylist: () => ({
type: SET_FOCUSED_WINDOW,
window: WINDOWS.PLAYLIST
}),
close: () => ({ type: TOGGLE_PLAYLIST_WINDOW }),
toggleShade: togglePlaylistShadeMode,
toggleVisualizerStyle,
scrollUpFourTracks,
scrollDownFourTracks,
loadFilesFromReferences: (e, startIndex) =>
loadFilesFromReferences(e.dataTransfer.files, null, startIndex),
togglePlaylistShadeMode,
scrollVolume
};
const mapStateToProps = state => {
const {
windows: { focused },
display: { skinPlaylistStyle, playlistSize, playlistShade },
media: { duration },
playlist: { trackOrder }
} = state;
return {
offset: getScrollOffset(state),
maxTrackIndex: trackOrder.length - 1,
playlistWindowPixelSize: getPlaylistWindowPixelSize(state),
focused,
skinPlaylistStyle,
playlistSize,
playlistShade,
duration
};
};
export default connect(mapStateToProps, mapDispatchToProps)(PlaylistWindow);