diff --git a/js/actionCreators/index.ts b/js/actionCreators/index.ts index 9a5a1b94..76844812 100644 --- a/js/actionCreators/index.ts +++ b/js/actionCreators/index.ts @@ -3,7 +3,9 @@ import { STOP, TOGGLE_VISUALIZER_STYLE, CLOSE_REQUESTED, - MINIMIZE_WINAMP + MINIMIZE_WINAMP, + SET_FOCUS, + UNSET_FOCUS } from "../actionTypes"; import { Dispatchable } from "../types"; @@ -98,3 +100,11 @@ export function toggleVisualizerStyle(): Dispatchable { export function minimize(): Dispatchable { return { type: MINIMIZE_WINAMP }; } + +export function setFocus(input: string): Dispatchable { + return { type: SET_FOCUS, input }; +} + +export function unsetFocus(): Dispatchable { + return { type: UNSET_FOCUS }; +} diff --git a/js/components/Balance.js b/js/components/Balance.js deleted file mode 100644 index db2b79c9..00000000 --- a/js/components/Balance.js +++ /dev/null @@ -1,33 +0,0 @@ -import React from "react"; -import { connect } from "react-redux"; - -import { setBalance } from "../actionCreators"; -import { SET_FOCUS, UNSET_FOCUS } from "../actionTypes"; - -const Balance = props => ( - -); - -const mapDispatchToProps = dispatch => ({ - handleChange: e => dispatch(setBalance(e.target.value)), - showMarquee: () => dispatch({ type: SET_FOCUS, input: "balance" }), - hideMarquee: () => dispatch({ type: UNSET_FOCUS }) -}); - -export default connect( - state => ({ balance: state.media.balance }), - mapDispatchToProps -)(Balance); diff --git a/js/components/Balance.tsx b/js/components/Balance.tsx new file mode 100644 index 00000000..11c0b9d2 --- /dev/null +++ b/js/components/Balance.tsx @@ -0,0 +1,49 @@ +import React, { ChangeEvent } from "react"; +import { connect } from "react-redux"; + +import { setBalance } from "../actionCreators"; +import * as Actions from "../actionCreators"; +import { Dispatch, AppState } from "../types"; +import * as Selectors from "../selectors"; + +interface Props { + id?: string; + balance: number; + showMarquee(): void; + hideMarquee(): void; + setBalance(e: ChangeEvent): void; + style?: React.CSSProperties; + className?: string; +} + +const Balance = (props: Props) => ( + +); + +const mapStateToProps = (state: AppState) => ({ + balance: Selectors.getBalance(state) +}); +const mapDispatchToProps = (dispatch: Dispatch) => ({ + setBalance: (e: ChangeEvent) => + dispatch(setBalance(Number((e.target as HTMLInputElement).value))), + showMarquee: () => dispatch(Actions.setFocus("balance")), + hideMarquee: () => dispatch(Actions.unsetFocus()) +}); + +export default connect( + mapStateToProps, + mapDispatchToProps +)(Balance); diff --git a/js/components/Volume.tsx b/js/components/Volume.tsx index e7ffc81e..21e75ed1 100644 --- a/js/components/Volume.tsx +++ b/js/components/Volume.tsx @@ -1,9 +1,7 @@ import React, { ChangeEvent } from "react"; import { connect } from "react-redux"; -import { setVolume } from "../actionCreators"; - -import { SET_FOCUS, UNSET_FOCUS } from "../actionTypes"; import { AppState, Dispatch } from "../types"; +import * as Actions from "../actionCreators"; import * as Selectors from "../selectors"; interface Props { @@ -38,10 +36,10 @@ const mapStateToProps = (state: AppState) => ({ }); const mapDispatchToProps = (dispatch: Dispatch) => ({ - showMarquee: () => dispatch({ type: SET_FOCUS, input: "volume" }), - hideMarquee: () => dispatch({ type: UNSET_FOCUS }), + showMarquee: () => dispatch(Actions.setFocus("volume")), + hideMarquee: () => dispatch(Actions.unsetFocus()), setVolume: (e: ChangeEvent) => - dispatch(setVolume(Number((e.target as HTMLInputElement).value))) + dispatch(Actions.setVolume(Number((e.target as HTMLInputElement).value))) }); export default connect( diff --git a/js/selectors.ts b/js/selectors.ts index 3767db8f..6bd12dca 100644 --- a/js/selectors.ts +++ b/js/selectors.ts @@ -400,5 +400,6 @@ export const getVisualizerStyle = (state: AppState) => fromDisplay.getVisualizerStyle(state.display); export const getVolume = (state: AppState) => state.media.volume; +export const getBalance = (state: AppState) => state.media.balance; export const getChannels = (state: AppState) => state.media.channels;