import React from "react"; import { connect } from "react-redux"; 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 }: StateProps & DispatchProps) => (
alert("Not supported in Webamp")} />
addDirAtIndex(nextIndex)} />
addFilesAtIndex(nextIndex)} /> ); const mapStateToProps = (state: AppState): StateProps => ({ nextIndex: getTrackCount(state) }); const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({ addFilesAtIndex: async nextIndex => { const fileReferences = await promptForFileReferences(); dispatch(addTracksFromReferences(fileReferences, null, nextIndex)); }, addDirAtIndex: async nextIndex => { if (!DIR_SUPPORT) { alert("Not supported in your browser"); return; } const fileReferences = await promptForFileReferences({ directory: true }); dispatch(addTracksFromReferences(fileReferences, null, nextIndex)); } }); export default connect( mapStateToProps, mapDispatchToProps )(AddMenu);