2018-10-30 19:15:19 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
|
|
|
Copyright 2017 New Vector Ltd
|
|
|
|
Copyright 2018 New Vector Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
2018-12-18 12:34:26 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2018-10-30 19:15:19 +03:00
|
|
|
import dis from '../../../dispatcher';
|
|
|
|
|
|
|
|
export default class HeaderButtons extends React.Component {
|
|
|
|
constructor(props, initialPhase) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2018-12-17 17:55:26 +03:00
|
|
|
phase: props.collapsedRhs ? null : initialPhase,
|
2018-10-30 19:15:19 +03:00
|
|
|
isUserPrivilegedInGroup: null,
|
|
|
|
};
|
|
|
|
this.onAction = this.onAction.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
dis.unregister(this.dispatcherRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
setPhase(phase, extras) {
|
|
|
|
// TODO: delay?
|
|
|
|
dis.dispatch(Object.assign({
|
|
|
|
action: 'view_right_panel_phase',
|
|
|
|
phase: phase,
|
|
|
|
}, extras));
|
|
|
|
}
|
|
|
|
|
2018-12-18 17:36:54 +03:00
|
|
|
isPhase(phases) {
|
|
|
|
if (this.props.collapsedRhs) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Array.isArray(phases)) {
|
|
|
|
return phases.includes(this.state.phase);
|
|
|
|
} else {
|
|
|
|
return phases === this.state.phase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-30 19:15:19 +03:00
|
|
|
onAction(payload) {
|
|
|
|
if (payload.action === "view_right_panel_phase") {
|
2018-12-17 17:22:02 +03:00
|
|
|
// 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 {
|
2018-12-18 17:33:45 +03:00
|
|
|
if (this.props.collapsedRhs && payload.fromHeader) {
|
2018-12-17 17:22:02 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'show_right_panel',
|
|
|
|
});
|
2018-12-18 18:27:17 +03:00
|
|
|
// 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}));
|
2018-12-17 17:22:02 +03:00
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
phase: payload.phase,
|
|
|
|
});
|
|
|
|
}
|
2018-10-30 19:15:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
// inline style as this will be swapped around in future commits
|
2019-02-12 22:04:24 +03:00
|
|
|
return <div className="mx_HeaderButtons">
|
2018-10-30 19:15:19 +03:00
|
|
|
{ this.renderButtons() }
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
}
|
2018-12-18 12:34:26 +03:00
|
|
|
|
|
|
|
HeaderButtons.propTypes = {
|
|
|
|
collapsedRhs: PropTypes.bool,
|
|
|
|
};
|