Type PlaylistWindow

This commit is contained in:
Jordan Eldredge 2018-10-11 22:15:43 -07:00
parent b6ad8044cf
commit b8894a7e7c
4 changed files with 60 additions and 26 deletions

View file

@ -70,7 +70,7 @@ const SKIN_FILENAME_MATCHER = new RegExp("(wsz|zip)$", "i");
const EQF_FILENAME_MATCHER = new RegExp("eqf$", "i");
export function loadFilesFromReferences(
fileReferences: FileList,
loadStyle = LOAD_STYLE.PLAY,
loadStyle: LoadStyle | null = LOAD_STYLE.PLAY,
atIndex: number | undefined = undefined
): Dispatchable {
return dispatch => {

View file

@ -96,8 +96,8 @@ interface ContextMenuProps {
children: React.ReactNode;
offsetTop: number;
offsetLeft: number;
top: boolean;
bottom: boolean;
top?: boolean;
bottom?: boolean;
selected: boolean;
zIndex: number;
}

View file

@ -5,8 +5,7 @@ interface Coord {
y: number;
}
interface Props {
loadFilesFromReferences: () => void;
interface Props extends React.HTMLAttributes<HTMLDivElement> {
handleDrop(e: React.DragEvent<HTMLDivElement>, coord: Coord): void;
}
@ -31,8 +30,6 @@ export default class DropTarget extends React.Component<Props> {
render() {
const {
// eslint-disable-next-line no-shadow, no-unused-vars
loadFilesFromReferences,
// eslint-disable-next-line no-shadow, no-unused-vars
handleDrop,
...passThroughProps

View file

@ -36,9 +36,44 @@ import TrackList from "./TrackList";
import ScrollBar from "./ScrollBar";
import "../../../css/playlist-window.css";
import { AppState, PlaylistStyle, Dispatch } from "../../types";
class PlaylistWindow extends React.Component {
_handleDrop = (e, targetCoords) => {
interface StateProps {
offset: number;
maxTrackIndex: number;
playlistWindowPixelSize: { width: number; height: number };
focused: string;
skinPlaylistStyle: PlaylistStyle;
playlistSize: [number, number];
playlistShade: boolean;
duration: number | null;
}
interface DispatchProps {
focusPlaylist(): void;
close(): void;
toggleShade(): void;
toggleVisualizerStyle(): void;
scrollUpFourTracks(): void;
scrollDownFourTracks(): void;
loadFilesFromReferences(
e: React.DragEvent<HTMLDivElement>,
startIndex: number
): void;
scrollVolume(e: React.WheelEvent<HTMLDivElement>): void;
}
interface OwnProps {
analyser: AnalyserNode;
}
type Props = StateProps & DispatchProps & OwnProps;
class PlaylistWindow extends React.Component<Props> {
_handleDrop = (
e: React.DragEvent<HTMLDivElement>,
targetCoords: { x: number; y: number }
) => {
const top = e.clientY - targetCoords.y;
const atIndex = clamp(
this.props.offset + Math.round((top - 23) / TRACK_HEIGHT),
@ -147,25 +182,27 @@ class PlaylistWindow extends React.Component {
}
}
const mapDispatchToProps = {
focusPlaylist: () => ({
type: SET_FOCUSED_WINDOW,
window: WINDOWS.PLAYLIST
}),
close: () => closeWindow("playlist"),
toggleShade: togglePlaylistShadeMode,
toggleVisualizerStyle,
scrollUpFourTracks,
scrollDownFourTracks,
loadFilesFromReferences: (e, startIndex) =>
loadFilesFromReferences(e.dataTransfer.files, null, startIndex),
scrollVolume
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => {
return {
focusPlaylist: () => ({
type: SET_FOCUSED_WINDOW,
window: WINDOWS.PLAYLIST
}),
close: () => closeWindow("playlist"),
toggleShade: togglePlaylistShadeMode,
toggleVisualizerStyle,
scrollUpFourTracks,
scrollDownFourTracks,
loadFilesFromReferences: (e, startIndex) =>
loadFilesFromReferences(e.dataTransfer.files, null, startIndex),
scrollVolume
};
};
const mapStateToProps = state => {
const mapStateToProps = (state: AppState): StateProps => {
const {
windows: { focused },
media: { duration },
media: { length },
playlist: { trackOrder }
} = state;
@ -176,8 +213,8 @@ const mapStateToProps = state => {
focused,
skinPlaylistStyle: getSkinPlaylistStyle(state),
playlistSize: getWindowSize(state)("playlist"),
playlistShade: getWindowShade(state)("playlist"),
duration
playlistShade: Boolean(getWindowShade(state)("playlist")),
duration: length
};
};