add togglePhase method, where we can show the panel if needed

without needing to resort to redispatching the original action
This commit is contained in:
Bruno Windels 2019-04-10 13:20:03 +02:00
parent 04710e6ca0
commit 5fb9276ef3

View file

@ -40,14 +40,36 @@ export default class HeaderButtons extends React.Component {
dis.unregister(this.dispatcherRef); dis.unregister(this.dispatcherRef);
} }
componentDidUpdate(prevProps) {
if (!prevProps.collapsedRhs && this.props.collapsedRhs) {
this.setState({
phase: null,
});
}
}
setPhase(phase, extras) { setPhase(phase, extras) {
// TODO: delay? if (this.props.collapsedRhs) {
dis.dispatch({
action: 'show_right_panel',
});
}
dis.dispatch(Object.assign({ dis.dispatch(Object.assign({
action: 'view_right_panel_phase', action: 'view_right_panel_phase',
phase: phase, phase: phase,
}, extras)); }, extras));
} }
togglePhase(phase) {
if (this.state.phase === phase) {
dis.dispatch({
action: 'hide_right_panel',
});
} else {
this.setPhase(phase);
}
}
isPhase(phases) { isPhase(phases) {
if (this.props.collapsedRhs) { if (this.props.collapsedRhs) {
return false; return false;
@ -61,30 +83,11 @@ export default class HeaderButtons extends React.Component {
onAction(payload) { onAction(payload) {
if (payload.action === "view_right_panel_phase") { if (payload.action === "view_right_panel_phase") {
// only actions coming from header buttons should collapse the right panel
if (this.state.phase === payload.phase && payload.fromHeader) {
dis.dispatch({
action: 'hide_right_panel',
});
this.setState({
phase: null,
});
} else {
if (this.props.collapsedRhs && payload.fromHeader) {
dis.dispatch({
action: 'show_right_panel',
});
// emit payload again as the RightPanel didn't exist up
// till show_right_panel, just without the fromHeader flag
// as that would hide the right panel again
dis.dispatch(Object.assign({}, payload, {fromHeader: false}));
}
this.setState({ this.setState({
phase: payload.phase, phase: payload.phase,
}); });
} }
} }
}
render() { render() {
// inline style as this will be swapped around in future commits // inline style as this will be swapped around in future commits