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';
|
|
|
|
import { _t } from '../../../languageHandler';
|
|
|
|
import HeaderButton from './HeaderButton';
|
2020-07-18 14:08:20 +03:00
|
|
|
import HeaderButtons, {HeaderKind} from './HeaderButtons';
|
|
|
|
import {RightPanelPhases} from "../../../stores/RightPanelStorePhases";
|
2020-05-14 06:03:12 +03:00
|
|
|
import {Action} from "../../../dispatcher/actions";
|
|
|
|
import {ActionPayload} from "../../../dispatcher/payloads";
|
2020-07-18 15:26:53 +03:00
|
|
|
import {ViewUserPayload} from "../../../dispatcher/payloads/ViewUserPayload";
|
2018-10-30 19:15:19 +03:00
|
|
|
|
2019-04-11 14:31:21 +03:00
|
|
|
const GROUP_PHASES = [
|
2020-07-18 14:08:20 +03:00
|
|
|
RightPanelPhases.GroupMemberInfo,
|
|
|
|
RightPanelPhases.GroupMemberList,
|
2019-04-11 14:31:21 +03:00
|
|
|
];
|
|
|
|
const ROOM_PHASES = [
|
2020-07-18 14:08:20 +03:00
|
|
|
RightPanelPhases.GroupRoomList,
|
|
|
|
RightPanelPhases.GroupRoomInfo,
|
2019-04-11 14:31:21 +03:00
|
|
|
];
|
|
|
|
|
2020-07-18 15:26:53 +03:00
|
|
|
interface IProps {}
|
|
|
|
|
2018-10-30 19:15:19 +03:00
|
|
|
export default class GroupHeaderButtons extends HeaderButtons {
|
2020-07-18 15:26:53 +03:00
|
|
|
constructor(props: IProps) {
|
2020-07-18 14:08:20 +03:00
|
|
|
super(props, HeaderKind.Group);
|
2020-07-30 13:28:07 +03:00
|
|
|
this.onMembersClicked = this.onMembersClicked.bind(this);
|
|
|
|
this.onRoomsClicked = this.onRoomsClicked.bind(this);
|
2018-10-30 19:15:19 +03:00
|
|
|
}
|
|
|
|
|
2020-07-30 13:43:13 +03:00
|
|
|
protected onAction(payload: ActionPayload) {
|
2020-05-14 06:03:12 +03:00
|
|
|
if (payload.action === Action.ViewUser) {
|
2020-07-18 15:26:53 +03:00
|
|
|
if ((payload as ViewUserPayload).member) {
|
2020-07-29 14:29:29 +03:00
|
|
|
this.setPhase(RightPanelPhases.RoomMemberInfo, {member: payload.member});
|
2018-10-30 19:15:19 +03:00
|
|
|
} else {
|
2020-07-18 14:08:20 +03:00
|
|
|
this.setPhase(RightPanelPhases.GroupMemberList);
|
2018-10-30 19:15:19 +03:00
|
|
|
}
|
|
|
|
} else if (payload.action === "view_group") {
|
2020-07-18 14:08:20 +03:00
|
|
|
this.setPhase(RightPanelPhases.GroupMemberList);
|
2018-10-30 19:15:19 +03:00
|
|
|
} else if (payload.action === "view_group_room") {
|
2019-12-06 09:58:19 +03:00
|
|
|
this.setPhase(
|
2020-07-18 14:08:20 +03:00
|
|
|
RightPanelPhases.GroupRoomInfo,
|
2019-12-06 09:58:19 +03:00
|
|
|
{groupRoomId: payload.groupRoomId, groupId: payload.groupId},
|
|
|
|
);
|
2018-10-30 19:15:19 +03:00
|
|
|
} else if (payload.action === "view_group_room_list") {
|
2020-07-18 14:08:20 +03:00
|
|
|
this.setPhase(RightPanelPhases.GroupRoomList);
|
2018-10-30 19:15:19 +03:00
|
|
|
} else if (payload.action === "view_group_member_list") {
|
2020-07-18 14:08:20 +03:00
|
|
|
this.setPhase(RightPanelPhases.GroupMemberList);
|
2018-10-30 19:15:19 +03:00
|
|
|
} else if (payload.action === "view_group_user") {
|
2020-07-29 14:29:29 +03:00
|
|
|
this.setPhase(RightPanelPhases.GroupMemberInfo, {member: payload.member});
|
2018-10-30 19:15:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-30 13:28:07 +03:00
|
|
|
private onMembersClicked() {
|
2020-07-18 14:08:20 +03:00
|
|
|
if (this.state.phase === RightPanelPhases.GroupMemberInfo) {
|
2020-01-05 23:31:07 +03:00
|
|
|
// send the active phase to trigger a toggle
|
2020-07-18 14:08:20 +03:00
|
|
|
this.setPhase(RightPanelPhases.GroupMemberInfo);
|
2020-01-05 23:31:07 +03:00
|
|
|
} else {
|
|
|
|
// This toggles for us, if needed
|
2020-07-18 14:08:20 +03:00
|
|
|
this.setPhase(RightPanelPhases.GroupMemberList);
|
2020-01-05 23:31:07 +03:00
|
|
|
}
|
2019-04-11 14:22:47 +03:00
|
|
|
}
|
|
|
|
|
2020-07-30 13:28:07 +03:00
|
|
|
private onRoomsClicked() {
|
2019-12-06 09:28:06 +03:00
|
|
|
// This toggles for us, if needed
|
2020-07-18 14:08:20 +03:00
|
|
|
this.setPhase(RightPanelPhases.GroupRoomList);
|
2019-04-11 14:22:47 +03:00
|
|
|
}
|
|
|
|
|
2018-10-30 19:15:19 +03:00
|
|
|
renderButtons() {
|
|
|
|
return [
|
2019-02-12 20:31:47 +03:00
|
|
|
<HeaderButton key="groupMembersButton" name="groupMembersButton"
|
|
|
|
title={_t('Members')}
|
2019-04-11 14:31:21 +03:00
|
|
|
isHighlighted={this.isPhase(GROUP_PHASES)}
|
2020-07-30 13:28:07 +03:00
|
|
|
onClick={this.onMembersClicked}
|
2018-10-30 19:15:19 +03:00
|
|
|
analytics={['Right Panel', 'Group Member List Button', 'click']}
|
|
|
|
/>,
|
2019-02-12 20:31:47 +03:00
|
|
|
<HeaderButton key="roomsButton" name="roomsButton"
|
|
|
|
title={_t('Rooms')}
|
2019-04-11 14:31:21 +03:00
|
|
|
isHighlighted={this.isPhase(ROOM_PHASES)}
|
2020-07-30 13:28:07 +03:00
|
|
|
onClick={this.onRoomsClicked}
|
2018-10-30 19:15:19 +03:00
|
|
|
analytics={['Right Panel', 'Group Room List Button', 'click']}
|
2018-10-31 14:20:10 +03:00
|
|
|
/>,
|
2018-10-30 19:15:19 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|