From b6ad8044cff2484d9ab8aaa8bc41de2344767263 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Thu, 11 Oct 2018 21:59:57 -0700 Subject: [PATCH] Type AddMenu --- js/actionCreators/files.ts | 2 +- .../{AddMenu.js => AddMenu.tsx} | 23 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) rename js/components/PlaylistWindow/{AddMenu.js => AddMenu.tsx} (74%) diff --git a/js/actionCreators/files.ts b/js/actionCreators/files.ts index e319d216..b930f745 100644 --- a/js/actionCreators/files.ts +++ b/js/actionCreators/files.ts @@ -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 => ({ diff --git a/js/components/PlaylistWindow/AddMenu.js b/js/components/PlaylistWindow/AddMenu.tsx similarity index 74% rename from js/components/PlaylistWindow/AddMenu.js rename to js/components/PlaylistWindow/AddMenu.tsx index dbdb1ae8..acb44b11 100644 --- a/js/components/PlaylistWindow/AddMenu.js +++ b/js/components/PlaylistWindow/AddMenu.tsx @@ -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) => (
alert("Not supported in Webamp")} />
addDirAtIndex(nextIndex)} /> @@ -22,11 +39,11 @@ const AddMenu = ({ nextIndex, addFilesAtIndex, addDirAtIndex }) => ( ); -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));