diff --git a/js/actionTypes.js b/js/actionTypes.js index 85111ce6..be4b44c9 100644 --- a/js/actionTypes.js +++ b/js/actionTypes.js @@ -70,3 +70,4 @@ export const NETWORK_CONNECTED = "NETWORK_CONNECTED"; export const NETWORK_DISCONNECTED = "NETWORK_DISCONNECTED"; export const UPDATE_WINDOW_POSITIONS = "UPDATE_WINDOW_POSITIONS"; export const CHANNEL_COUNT_CHANGED = "CHANNEL_COUNT_CHANGED"; +export const GEN_WINDOW_SIZE_CHANGED = "GEN_WINDOW_SIZE_CHANGED"; diff --git a/js/components/GenWindow/index.js b/js/components/GenWindow/index.js index 981e176e..803e67e9 100644 --- a/js/components/GenWindow/index.js +++ b/js/components/GenWindow/index.js @@ -4,7 +4,11 @@ import PropTypes from "prop-types"; import classnames from "classnames"; import "../../../css/gen-window.css"; -import { SET_FOCUSED_WINDOW, CLOSE_GEN_WINDOW } from "../../actionTypes"; +import { + SET_FOCUSED_WINDOW, + CLOSE_GEN_WINDOW, + GEN_WINDOW_SIZE_CHANGED +} from "../../actionTypes"; import { scrollVolume } from "../../actionCreators"; import { getWindowPixelSize } from "../../selectors"; import ResizeTarget from "../ResizeTarget"; @@ -25,73 +29,65 @@ const CHROME_WIDTH = 19; const CHROME_HEIGHT = 34; // Named export for testing -export class GenWindow extends React.Component { - constructor(props) { - super(props); - this.state = { windowSize: [0, 0] }; - } - render() { - const { - selected, - children, - close, - title, - setFocus, - windowId, - scrollVolume: handleWheel - } = this.props; - const { width, height } = getWindowPixelSize(this.state.windowSize); - return ( -
setFocus(windowId)} - onWheel={handleWheel} - style={{ width, height }} - > -
-
-
-
-
- {title} -
-
-
-
-
close(windowId)} - /> -
+export const GenWindow = ({ + selected, + children, + close, + title, + setFocus, + windowId, + windowSize, + genWindowSizeChanged, + scrollVolume: handleWheel +}) => { + const { width, height } = getWindowPixelSize(windowSize); + return ( +
setFocus(windowId)} + onWheel={handleWheel} + style={{ width, height }} + > +
+
+
+
+
+ {title}
-
-
-
-
-
- {children({ - width: width - CHROME_WIDTH, - height: height - CHROME_HEIGHT - })} -
-
-
-
-
-
-
-
- this.setState({ windowSize: size })} - id={"gen-resize-target"} - /> -
+
+
+
+
close(windowId)} />
- ); - } -} +
+
+
+
+
+ {children({ + width: width - CHROME_WIDTH, + height: height - CHROME_HEIGHT + })} +
+
+
+
+
+
+
+
+ genWindowSizeChanged(windowId, size)} + id={"gen-resize-target"} + /> +
+
+
+ ); +}; GenWindow.propTypes = { title: PropTypes.string.isRequired, @@ -102,13 +98,19 @@ GenWindow.propTypes = { }; const mapStateToProps = (state, ownProps) => ({ - selected: state.windows.focused === ownProps.windowId + selected: state.windows.focused === ownProps.windowId, + windowSize: state.windows.genWindows[ownProps.windowId].size }); const mapDispatchToProps = { setFocus: windowId => ({ type: SET_FOCUSED_WINDOW, window: windowId }), close: windowId => ({ type: CLOSE_GEN_WINDOW, windowId }), - scrollVolume + scrollVolume, + genWindowSizeChanged: (windowId, size) => ({ + type: GEN_WINDOW_SIZE_CHANGED, + windowId, + size + }) }; export default connect(mapStateToProps, mapDispatchToProps)(GenWindow); diff --git a/js/reducers/windows.js b/js/reducers/windows.js index cfedd46d..4ddddacb 100644 --- a/js/reducers/windows.js +++ b/js/reducers/windows.js @@ -9,7 +9,8 @@ import { CLOSE_GEN_WINDOW, OPEN_GEN_WINDOW, ADD_GEN_WINDOW, - UPDATE_WINDOW_POSITIONS + UPDATE_WINDOW_POSITIONS, + GEN_WINDOW_SIZE_CHANGED } from "../actionTypes"; const defaultWindowsState = { @@ -60,7 +61,7 @@ const windows = (state = defaultWindowsState, action) => { ...state, genWindows: { ...state.genWindows, - [action.windowId]: { title: action.title, open: true } + [action.windowId]: { title: action.title, open: true, size: [0, 0] } } }; case OPEN_GEN_WINDOW: @@ -74,6 +75,17 @@ const windows = (state = defaultWindowsState, action) => { } } }; + case GEN_WINDOW_SIZE_CHANGED: + return { + ...state, + genWindows: { + ...state.genWindows, + [action.windowId]: { + ...state.genWindows[action.windowId], + size: action.size + } + } + }; case UPDATE_WINDOW_POSITIONS: return { ...state,