From b0346774be924c36af82eb9e1addf6427233d8d5 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Mon, 1 Oct 2018 12:50:21 -0700 Subject: [PATCH] Revert "Add types for WindowManager" This reverts commit 0a7f258b6400ec66d39930e88da6f9e36e465ef8. --- .../{WindowManager.tsx => WindowManager.js} | 62 +++++++------------ js/snapUtils.ts | 8 +-- 2 files changed, 26 insertions(+), 44 deletions(-) rename js/components/{WindowManager.tsx => WindowManager.js} (70%) diff --git a/js/components/WindowManager.tsx b/js/components/WindowManager.js similarity index 70% rename from js/components/WindowManager.tsx rename to js/components/WindowManager.js index 5c6a8951..4a9fbba7 100644 --- a/js/components/WindowManager.tsx +++ b/js/components/WindowManager.js @@ -1,7 +1,7 @@ -import React, { ReactNode } from "react"; +import React from "react"; +import PropTypes from "prop-types"; import { connect } from "react-redux"; -import { Box, Diff } from "../snapUtils"; import * as SnapUtils from "../snapUtils"; import * as Selectors from "../selectors"; import { @@ -9,31 +9,14 @@ import { windowsHaveBeenCentered, centerWindowsIfNeeded } from "../actionCreators"; -import { - WindowInfo, - Dispatch, - WindowPositions, - AppState, - WindowId -} from "../types"; -const abuts = (a: Box, b: Box) => { +const abuts = (a, b) => { // TODO: This is kinda a hack. They should really be touching, not just within snapping distance. // Also, overlapping should not count. const wouldMoveTo = SnapUtils.snap(a, b); return wouldMoveTo.x !== undefined || wouldMoveTo.y !== undefined; }; -interface Props { - centerWindowsIfNeeded(container: HTMLElement): void; - container: HTMLElement; - windowsInfo: WindowInfo[]; - browserWindowSize: { height: number; width: number }; - updateWindowPositions(positions: WindowPositions, center: boolean): void; - getWindowHidden(windowId: WindowId): boolean; - windows: { [windowId: string]: ReactNode }; -} - -class WindowManager extends React.Component { +class WindowManager extends React.Component { componentDidMount() { this.props.centerWindowsIfNeeded(this.props.container); } @@ -42,15 +25,12 @@ class WindowManager extends React.Component { this.props.centerWindowsIfNeeded(this.props.container); } - movingAndStationaryNodes(key: WindowId): [WindowInfo[], WindowInfo[]] { + movingAndStationaryNodes(key) { const windows = this.props.windowsInfo.filter( w => this.props.windows[w.key] != null && !this.props.getWindowHidden(w.key) ); const targetNode = windows.find(node => node.key === key); - if (targetNode == null) { - throw new Error("Tried to move a node that does not exist"); - } let movingSet = new Set([targetNode]); // Only the main window brings other windows along. @@ -65,8 +45,8 @@ class WindowManager extends React.Component { return [moving, stationary]; } - handleMouseDown = (key: WindowId, e: React.MouseEvent) => { - if (!(e.target as HTMLElement).classList.contains("draggable")) { + handleMouseDown = (key, e) => { + if (!e.target.classList.contains("draggable")) { return; } // Prevent dragging from highlighting text. @@ -79,7 +59,7 @@ class WindowManager extends React.Component { const box = SnapUtils.boundingBox(moving); - const handleMouseMove = (ee: MouseEvent) => { + const handleMouseMove = ee => { const proposedDiff = { x: ee.clientX - mouseStart.x, y: ee.clientY - mouseStart.y @@ -111,13 +91,10 @@ class WindowManager extends React.Component { withinDiff ); - const windowPositionDiff = moving.reduce( - (diff: { [windowId: string]: Diff }, window) => { - diff[window.key] = SnapUtils.applyDiff(window, finalDiff); - return diff; - }, - {} - ); + const windowPositionDiff = moving.reduce((diff, window) => { + diff[window.key] = SnapUtils.applyDiff(window, finalDiff); + return diff; + }, {}); this.props.updateWindowPositions(windowPositionDiff, false); }; @@ -132,7 +109,7 @@ class WindowManager extends React.Component { }; render() { - const style: React.CSSProperties = { + const style = { position: "absolute", top: 0, left: 0 @@ -154,19 +131,24 @@ class WindowManager extends React.Component { } } -const mapStateToProps = (state: AppState) => ({ +WindowManager.propTypes = { + windows: PropTypes.object.isRequired, + container: PropTypes.instanceOf(Element).isRequired +}; + +const mapStateToProps = state => ({ windowsInfo: Selectors.getWindowsInfo(state), getWindowHidden: Selectors.getWindowHidden(state), getWindowOpen: Selectors.getWindowOpen(state), browserWindowSize: Selectors.getBrowserWindowSize(state) }); -const mapDispatchToProps = (dispatch: Dispatch) => { +const mapDispatchToProps = dispatch => { return { - updateWindowPositions: (positions: WindowPositions, centered: boolean) => + updateWindowPositions: (positions, centered) => dispatch(updateWindowPositions(positions, centered)), windowsHaveBeenCentered: () => dispatch(windowsHaveBeenCentered()), - centerWindowsIfNeeded: (container: HTMLElement) => + centerWindowsIfNeeded: container => dispatch(centerWindowsIfNeeded(container)) }; }; diff --git a/js/snapUtils.ts b/js/snapUtils.ts index 99eb1eb8..50555851 100644 --- a/js/snapUtils.ts +++ b/js/snapUtils.ts @@ -3,7 +3,7 @@ interface Point { y: number; } -export interface Diff { +interface Diff { x?: number; y?: number; } @@ -64,7 +64,7 @@ export const snap = (boxA: Box, boxB: Box) => { return { x, y }; }; -export const snapDiff = (a: Box, b: Box): Point => { +export const snapDiff = (a: Box, b: Box): Diff => { const newPos = snap(a, b); return { x: newPos.x === undefined ? 0 : newPos.x - a.x, @@ -73,7 +73,7 @@ export const snapDiff = (a: Box, b: Box): Point => { }; // TODO: Use the first x and y combo -export const snapDiffManyToMany = (as: Box[], bs: Box[]): Point => { +export const snapDiffManyToMany = (as: Box[], bs: Box[]): Diff => { let x: number | undefined = 0; let y: number | undefined = 0; for (const a of as) { @@ -120,7 +120,7 @@ export const snapWithin = (boxA: Box, boundingBox: BoundingBox): Diff => { return { x, y }; }; -export const snapWithinDiff = (a: Box, b: BoundingBox) => { +export const snapWithinDiff = (a: Box, b: Box) => { const newPos = snapWithin(a, b); return { x: newPos.x === undefined ? 0 : newPos.x - a.x,