From 6d9b30aeb279aadee75aaf380d0bac694970cfb6 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Tue, 9 Oct 2018 23:14:56 -0700 Subject: [PATCH] Type GenWindow --- js/actionCreators/media.ts | 4 +- .../GenWindow/{index.js => index.tsx} | 80 +++++++++++++------ 2 files changed, 59 insertions(+), 25 deletions(-) rename js/components/GenWindow/{index.js => index.tsx} (63%) diff --git a/js/actionCreators/media.ts b/js/actionCreators/media.ts index 703fb3b7..35b59ad4 100644 --- a/js/actionCreators/media.ts +++ b/js/actionCreators/media.ts @@ -120,7 +120,9 @@ export function adjustVolume(volumeDiff: number): Dispatchable { }; } -export function scrollVolume(e: WheelEvent): Dispatchable { +export function scrollVolume( + e: React.WheelEvent +): Dispatchable { e.preventDefault(); return (dispatch, getState) => { const currentVolume = getState().media.volume; diff --git a/js/components/GenWindow/index.js b/js/components/GenWindow/index.tsx similarity index 63% rename from js/components/GenWindow/index.js rename to js/components/GenWindow/index.tsx index ddc7b5e1..206227af 100644 --- a/js/components/GenWindow/index.js +++ b/js/components/GenWindow/index.tsx @@ -8,22 +8,58 @@ import { SET_FOCUSED_WINDOW } from "../../actionTypes"; import { scrollVolume, setWindowSize, closeWindow } from "../../actionCreators"; import { getWindowPixelSize } from "../../selectors"; import ResizeTarget from "../ResizeTarget"; +import { AppState, WindowId, Dispatch } from "../../types"; -const Text = ({ children }) => { +interface TextProps { + children: string; +} + +const Text = ({ children }: TextProps) => { const letters = children.split(""); - return letters.map((letter, i) => ( -
- )); + return ( + + {letters.map((letter, i) => ( +
+ ))} + + ); }; const CHROME_WIDTH = 19; const CHROME_HEIGHT = 34; +interface WindowSize { + width: number; + height: number; +} + +interface OwnProps { + windowId: WindowId; + children: (windowSize: WindowSize) => React.ReactNode; + title: string; +} + +interface DispatchProps { + setFocus: (windowId: WindowId) => void; + close: (windowId: WindowId) => void; + scrollVolume: (event: React.WheelEvent) => void; + setGenWindowSize: (windowId: WindowId, size: [number, number]) => void; +} + +interface StateProps { + windowSize: [number, number]; + selected: boolean; + height: number; + width: number; +} + +type Props = OwnProps & DispatchProps & StateProps; + // Named export for testing export const GenWindow = ({ selected, @@ -37,7 +73,7 @@ export const GenWindow = ({ scrollVolume: handleWheel, width, height -}) => { +}: Props) => { return (
{ +const mapStateToProps = (state: AppState, ownProps: OwnProps): StateProps => { const { width, height } = getWindowPixelSize(state)(ownProps.windowId); return { width, @@ -104,11 +132,15 @@ const mapStateToProps = (state, ownProps) => { }; }; -const mapDispatchToProps = { - setFocus: windowId => ({ type: SET_FOCUSED_WINDOW, window: windowId }), - close: windowId => closeWindow(windowId), - setGenWindowSize: setWindowSize, - scrollVolume +const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => { + return { + setFocus: (windowId: WindowId) => + dispatch({ type: SET_FOCUSED_WINDOW, window: windowId }), + close: (windowId: WindowId) => dispatch(closeWindow(windowId)), + setGenWindowSize: (windowId: WindowId, size: [number, number]) => + dispatch(setWindowSize(windowId, size)), + scrollVolume: e => dispatch(scrollVolume(e)) + }; }; export default connect(