Type AddMenu

This commit is contained in:
Jordan Eldredge 2018-10-11 21:59:57 -07:00
parent 36f1dd6ff1
commit b6ad8044cf
2 changed files with 21 additions and 4 deletions

View file

@ -56,7 +56,7 @@ const loadQueue = new LoadQueue({ threads: 4 });
export function addTracksFromReferences(
fileReferences: FileList,
loadStyle: LoadStyle,
loadStyle: LoadStyle | null,
atIndex: number | undefined
): Dispatchable {
const tracks: Track[] = Array.from(fileReferences).map(file => ({

View file

@ -4,17 +4,34 @@ import { getTrackCount } from "../../selectors";
import { addTracksFromReferences } from "../../actionCreators";
import { promptForFileReferences } from "../../fileUtils";
import PlaylistMenu from "./PlaylistMenu";
import { AppState, Dispatch } from "../../types";
interface StateProps {
nextIndex: number;
}
interface DispatchProps {
addFilesAtIndex(i: number): void;
addDirAtIndex(i: number): void;
}
const el = document.createElement("input");
el.type = "file";
// @ts-ingore
const DIR_SUPPORT =
// @ts-ignore
typeof el.webkitdirectory !== "undefined" ||
// @ts-ignore
typeof el.mozdirectory !== "undefined" ||
// @ts-ignore
typeof el.directory !== "undefined";
/* eslint-disable no-alert */
const AddMenu = ({ nextIndex, addFilesAtIndex, addDirAtIndex }) => (
const AddMenu = ({
nextIndex,
addFilesAtIndex,
addDirAtIndex
}: StateProps & DispatchProps) => (
<PlaylistMenu id="playlist-add-menu">
<div className="add-url" onClick={() => alert("Not supported in Webamp")} />
<div className="add-dir" onClick={() => addDirAtIndex(nextIndex)} />
@ -22,11 +39,11 @@ const AddMenu = ({ nextIndex, addFilesAtIndex, addDirAtIndex }) => (
</PlaylistMenu>
);
const mapStateToProps = state => ({
const mapStateToProps = (state: AppState): StateProps => ({
nextIndex: getTrackCount(state)
});
const mapDispatchToProps = dispatch => ({
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
addFilesAtIndex: async nextIndex => {
const fileReferences = await promptForFileReferences();
dispatch(addTracksFromReferences(fileReferences, null, nextIndex));