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
|
2019-12-06 09:28:06 +03:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2018-10-30 19:15:19 +03:00
|
|
|
|
|
|
|
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';
|
2020-05-14 05:41:41 +03:00
|
|
|
import dis from '../../../dispatcher/dispatcher';
|
2019-12-06 09:28:06 +03:00
|
|
|
import RightPanelStore from "../../../stores/RightPanelStore";
|
2020-07-18 14:04:48 +03:00
|
|
|
import {RightPanelPhases} from "../../../stores/RightPanelStorePhases";
|
|
|
|
import {Action} from '../../../dispatcher/actions';
|
2020-07-18 14:44:20 +03:00
|
|
|
import {SetRightPanelPhasePayload, SetRightPanelPhaseRefireParams} from '../../../dispatcher/payloads/SetRightPanelPhasePayload';
|
2019-12-06 09:28:06 +03:00
|
|
|
|
2020-07-18 14:04:48 +03:00
|
|
|
export enum HeaderKind {
|
|
|
|
Room = "room",
|
|
|
|
Group = "group",
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
headerKind: HeaderKind;
|
|
|
|
phase: RightPanelPhases;
|
|
|
|
}
|
2019-12-06 09:28:06 +03:00
|
|
|
|
2020-07-18 14:04:48 +03:00
|
|
|
interface IProps {}
|
2018-10-30 19:15:19 +03:00
|
|
|
|
2020-07-18 14:04:48 +03:00
|
|
|
export default class HeaderButtons extends React.Component<IProps, IState> {
|
2020-07-30 09:15:49 +03:00
|
|
|
private storeToken: ReturnType<RightPanelStore["addListener"]>;
|
2020-07-18 14:04:48 +03:00
|
|
|
private dispatcherRef: string;
|
2018-10-30 19:15:19 +03:00
|
|
|
|
2020-07-18 14:04:48 +03:00
|
|
|
constructor(props: IProps, kind: HeaderKind) {
|
|
|
|
super(props);
|
2019-12-06 09:28:06 +03:00
|
|
|
|
|
|
|
const rps = RightPanelStore.getSharedInstance();
|
2018-10-30 19:15:19 +03:00
|
|
|
this.state = {
|
2019-12-06 09:28:06 +03:00
|
|
|
headerKind: kind,
|
2020-07-18 14:04:48 +03:00
|
|
|
phase: kind === HeaderKind.Room ? rps.visibleRoomPanelPhase : rps.visibleGroupPanelPhase,
|
2018-10-30 19:15:19 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-03-31 23:14:17 +03:00
|
|
|
componentDidMount() {
|
2020-07-18 14:04:48 +03:00
|
|
|
this.storeToken = RightPanelStore.getSharedInstance().addListener(this.onRightPanelUpdate.bind(this));
|
|
|
|
this.dispatcherRef = dis.register(this.onAction.bind(this)); // used by subclasses
|
2018-10-30 19:15:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2020-07-18 14:04:48 +03:00
|
|
|
if (this.storeToken) this.storeToken.remove();
|
|
|
|
if (this.dispatcherRef) dis.unregister(this.dispatcherRef);
|
2019-12-07 00:50:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
onAction(payload) {
|
|
|
|
// Ignore - intended to be overridden by subclasses
|
2019-04-10 14:20:03 +03:00
|
|
|
}
|
|
|
|
|
2020-07-18 14:44:20 +03:00
|
|
|
setPhase(phase: RightPanelPhases, extras?: Partial<SetRightPanelPhaseRefireParams>) {
|
2020-07-18 14:08:20 +03:00
|
|
|
dis.dispatch<SetRightPanelPhasePayload>({
|
2020-07-18 14:04:48 +03:00
|
|
|
action: Action.SetRightPanelPhase,
|
2018-10-30 19:15:19 +03:00
|
|
|
phase: phase,
|
2019-12-06 09:28:06 +03:00
|
|
|
refireParams: extras,
|
|
|
|
});
|
2018-10-30 19:15:19 +03:00
|
|
|
}
|
|
|
|
|
2019-12-06 09:28:06 +03:00
|
|
|
isPhase(phases: string | string[]) {
|
2018-12-18 17:36:54 +03:00
|
|
|
if (Array.isArray(phases)) {
|
|
|
|
return phases.includes(this.state.phase);
|
|
|
|
} else {
|
|
|
|
return phases === this.state.phase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 09:28:06 +03:00
|
|
|
onRightPanelUpdate() {
|
|
|
|
const rps = RightPanelStore.getSharedInstance();
|
2020-07-18 14:04:48 +03:00
|
|
|
if (this.state.headerKind === HeaderKind.Room) {
|
2019-12-06 09:28:06 +03:00
|
|
|
this.setState({phase: rps.visibleRoomPanelPhase});
|
2020-07-18 14:04:48 +03:00
|
|
|
} else if (this.state.headerKind === HeaderKind.Group) {
|
2019-12-06 09:28:06 +03:00
|
|
|
this.setState({phase: rps.visibleGroupPanelPhase});
|
2018-10-30 19:15:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-18 14:04:48 +03:00
|
|
|
// XXX: Make renderButtons a prop
|
|
|
|
renderButtons(): JSX.Element[] {
|
|
|
|
// Ignore - intended to be overridden by subclasses
|
|
|
|
// Return empty fragment to satisfy the type
|
|
|
|
return [
|
|
|
|
<React.Fragment>
|
|
|
|
</React.Fragment>
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-10-30 19:15:19 +03:00
|
|
|
render() {
|
|
|
|
// inline style as this will be swapped around in future commits
|
2019-10-03 11:35:39 +03:00
|
|
|
return <div className="mx_HeaderButtons" role="tablist">
|
2019-12-06 09:28:06 +03:00
|
|
|
{this.renderButtons()}
|
2018-10-30 19:15:19 +03:00
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
}
|