Skip to content

Commit

Permalink
Save active pane state in redux store SuperblocksHQ#278
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Dec 12, 2018
1 parent 6610fae commit 7357749
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/actions/panes.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@ export const panesActions = {
type: panesActions.REMOVE_PANE,
data: { id }
}
},

SET_ACTIVE_PANE: 'SET_ACTIVE_PANE',
setActivePane(id) {
return {
type: panesActions.SET_ACTIVE_PANE,
data: { id }
};
}
};
6 changes: 3 additions & 3 deletions src/components/projecteditor/panes-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ export default class PanesHeader extends Component {
getClassnames(paneData) {
const cls = {};
cls[style.tab] = true;
cls[style.selected] = paneData.id == this.props.activePaneId; // TODO: activePaneId should be in redux store
cls[style.selected] = paneData.active;
return classnames(cls);
}

render() {
const html = this.props.panes.map((paneData, index) => {
const iconElement = this.props.paneComponents[index].getIcon(); // paneComponent are only needed to get an icon
const iconElement = this.props.paneComponents[index].getIcon();
const contextMenu = this.getContextMenuElement();

return (
Expand Down Expand Up @@ -85,7 +85,7 @@ export default class PanesHeader extends Component {

PanesHeader.propTypes = {
panes: PropTypes.array.isRequired,
paneComponents: PropTypes.array.isRequired,
paneComponents: PropTypes.array.isRequired, // paneComponents are only needed to get an icon. TODO: remove it as soon as possible
closeAllPanes: PropTypes.func,
closeAllOtherPanes: PropTypes.func,
tabClicked: PropTypes.func,
Expand Down
17 changes: 14 additions & 3 deletions src/components/projecteditor/panes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Panes extends Component {
constructor(props) {
super(props);
this.panes = [];
this.activePaneId = null;
this._activePaneId = null;
props.router.register('panes', this);
}

Expand All @@ -38,6 +38,15 @@ class Panes extends Component {
});
}

get activePaneId() {
return this._activePaneId;
}

set activePaneId(value) {
this._activePaneId = value;
this.props.setActivePane(value);
}

addWindow = (props, paneId) => {
var pane, newPaneWasAdded = false;
if (paneId) {
Expand Down Expand Up @@ -313,7 +322,6 @@ class Panes extends Component {
<div key="header" id="panes_header" className={style.header}>
<PanesHeader
panes={this.props.panes}
activePaneId={this.activePaneId}
paneComponents={this.panes}

closeAllPanes={this.closeAllPanes}
Expand Down Expand Up @@ -348,8 +356,11 @@ const mapDispatchToProps = (dispatch) => {
},
removePane: (id) => {
dispatch(panesActions.removePane(id))
},
setActivePane: (id) => {
dispatch(panesActions.setActivePane(id));
}
}
};
}

export default connect(mapStateToProps, mapDispatchToProps)(Panes);
7 changes: 7 additions & 0 deletions src/reducers/panes.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ export default function panesReducer(state = initialState, action) {
...state,
panes: state.panes.filter(p => p.id !== action.data.id)
};
case panesActions.SET_ACTIVE_PANE: {
const deactivatedPanes = replaceInArray(state.panes, p => p.active, p => ({ ...p, active: false }))
return {
...state,
panes: replaceInArray(deactivatedPanes, p => p.id === action.data.id, p => ({ ...p, active: true }))
};
}
case explorerActions.RENAME_FILE: {
return {
...state,
Expand Down

0 comments on commit 7357749

Please sign in to comment.