From de16d78294cf03f745587b7d097698b07040839a Mon Sep 17 00:00:00 2001 From: Jessie Keck <jessie.keck@gmail.com> Date: Thu, 28 Feb 2019 19:56:41 -0800 Subject: [PATCH] Update MAXIMIZE/MINIMIZE_WINDOW reducers to not overwrite windows --- src/components/WorkspaceMosaic.js | 15 +++++++-------- src/state/reducers/windows.js | 30 ++++++++++++++---------------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/components/WorkspaceMosaic.js b/src/components/WorkspaceMosaic.js index 6794ab3f6..c68e4223c 100644 --- a/src/components/WorkspaceMosaic.js +++ b/src/components/WorkspaceMosaic.js @@ -49,15 +49,14 @@ export class WorkspaceMosaic extends React.Component { const { windows, workspace } = this.props; let windowKeys = Object.keys(windows).sort(); const leaveKeys = getLeaves(workspace.layout); - console.log(Object.keys(windows)); // First, check to see if any windows are maximized - // const maximizedWindows = windowKeys.map(id => windows[id]).filter(window => window.maximized === true) - // if (maximizedWindows.length) { - // windowKeys = maximizedWindows.map(window => window.id); - // } - windowKeys = [windowKeys[0]]; - console.log(Object.keys(windows)); - // console.log(windowKeys.map(id => windows[id]).filter(window => window.maximized === true)); + const maximizedWindows = windowKeys + .map(id => windows[id]) + .filter(window => window.maximized === true); + + if (maximizedWindows.length) { + windowKeys = maximizedWindows.map(window => window.id); + } // Check every window is in the layout, and all layout windows are present // in store if (!windowKeys.every(e => leaveKeys.includes(e)) diff --git a/src/state/reducers/windows.js b/src/state/reducers/windows.js index b64220af7..75aaf837a 100644 --- a/src/state/reducers/windows.js +++ b/src/state/reducers/windows.js @@ -10,23 +10,21 @@ export const windowsReducer = (state = {}, action) => { return { ...state, [action.window.id]: action.window }; case ActionTypes.MAXIMIZE_WINDOW: - return Object.keys(state).reduce((object, key) => { - if (key === action.windowId) { - object[key] = state[key]; // eslint-disable-line no-param-reassign - object[key].maximized = true; // eslint-disable-line no-param-reassign - } - return object; - }, {}); - + return { + ...state, + [action.windowId]: { + ...state[action.windowId], + maximized: true, + }, + }; case ActionTypes.MINIMIZE_WINDOW: - return Object.keys(state).reduce((object, key) => { - if (key === action.windowId) { - object[key] = state[key]; // eslint-disable-line no-param-reassign - object[key].maximized = false; // eslint-disable-line no-param-reassign - } - return object; - }, {}); - + return { + ...state, + [action.windowId]: { + ...state[action.windowId], + maximized: false, + }, + }; case ActionTypes.UPDATE_WINDOW: return updateIn(state, [action.id], orig => merge(orig, action.payload)); -- GitLab