Require load style always be explicit

Fixes #687
This commit is contained in:
Jordan Eldredge 2018-10-21 15:49:54 -07:00
parent 4cf1550dea
commit 9f5c20d413
5 changed files with 19 additions and 9 deletions

View file

@ -56,7 +56,7 @@ const loadQueue = new LoadQueue({ threads: 4 });
export function addTracksFromReferences(
fileReferences: FileList,
loadStyle: LoadStyle | null,
loadStyle: LoadStyle,
atIndex: number | undefined
): Dispatchable {
const tracks: Track[] = Array.from(fileReferences).map(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: LoadStyle | null = LOAD_STYLE.PLAY,
loadStyle: LoadStyle = LOAD_STYLE.PLAY,
atIndex: number | undefined = undefined
): Dispatchable {
return dispatch => {
@ -206,7 +206,7 @@ export function fetchMediaDuration(url: string, id: number): Dispatchable {
export function loadMediaFiles(
tracks: Track[],
loadStyle: LoadStyle | null = null,
loadStyle: LoadStyle = LOAD_STYLE.NONE,
atIndex = 0
): Dispatchable {
return dispatch => {
@ -216,7 +216,7 @@ export function loadMediaFiles(
dispatch(removeAllTracks());
}
tracks.forEach((track, i) => {
const priority = i === 0 && loadStyle != null ? loadStyle : null;
const priority = i === 0 ? loadStyle : LOAD_STYLE.NONE;
dispatch(loadMediaFile(track, priority, atIndex + i));
});
};
@ -224,7 +224,7 @@ export function loadMediaFiles(
export function loadMediaFile(
track: Track,
priority: LoadStyle | null = null,
priority: LoadStyle = LOAD_STYLE.NONE,
atIndex = 0
): Dispatchable {
return dispatch => {
@ -253,6 +253,7 @@ export function loadMediaFile(
case LOAD_STYLE.PLAY:
dispatch({ type: PLAY_TRACK, id });
break;
case LOAD_STYLE.NONE:
default:
// If we're not going to load this right away,
// we should set duration on our own

View file

@ -21,6 +21,8 @@ import {
getSkinPlaylistStyle
} from "../../selectors";
import { LOAD_STYLE } from "../../constants";
import { clamp } from "../../utils";
import DropTarget from "../DropTarget";
import Visualizer from "../Visualizer";
@ -200,7 +202,13 @@ const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => {
scrollUpFourTracks: () => dispatch(scrollUpFourTracks()),
scrollDownFourTracks: () => dispatch(scrollDownFourTracks()),
loadFilesFromReferences: (e, startIndex) =>
dispatch(loadFilesFromReferences(e.dataTransfer.files, null, startIndex)),
dispatch(
loadFilesFromReferences(
e.dataTransfer.files,
LOAD_STYLE.NONE,
startIndex
)
),
scrollVolume: e => dispatch(scrollVolume(e))
};
};

View file

@ -28,7 +28,8 @@ export const WINDOWS = {
export const LOAD_STYLE: Record<LoadStyle, LoadStyle> = {
BUFFER: "BUFFER",
PLAY: "PLAY"
PLAY: "PLAY",
NONE: "NONE"
};
// TODO: Make this an enum?

View file

@ -424,7 +424,7 @@ export type MediaTagRequestStatus =
export type MediaStatus = "PLAYING" | "STOPPED" | "PAUSED";
export type LoadStyle = "BUFFER" | "PLAY";
export type LoadStyle = "BUFFER" | "PLAY" | "NONE";
export type TimeMode = "ELAPSED" | "REMAINING";

View file

@ -192,7 +192,7 @@ class Winamp {
appendTracks(tracks) {
const nextIndex = Selectors.getTrackCount(this.store.getState());
this.store.dispatch(
Actions.loadMediaFiles(tracks, LOAD_STYLE.BUFFER, nextIndex)
Actions.loadMediaFiles(tracks, LOAD_STYLE.NONE, nextIndex)
);
}