mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 19:56:47 +03:00
Use new right panel store for header buttons
This introduces a new dispatch action (unused, so far) and routes the buttons towards the RightPanelStore for processing.
This commit is contained in:
parent
6e882251bd
commit
ca0c393783
4 changed files with 121 additions and 82 deletions
|
@ -3,6 +3,7 @@ Copyright 2015, 2016 OpenMarket Ltd
|
||||||
Copyright 2017 Vector Creations Ltd
|
Copyright 2017 Vector Creations Ltd
|
||||||
Copyright 2017 New Vector Ltd
|
Copyright 2017 New Vector Ltd
|
||||||
Copyright 2018 New Vector Ltd
|
Copyright 2018 New Vector Ltd
|
||||||
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -20,21 +21,21 @@ limitations under the License.
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
import HeaderButton from './HeaderButton';
|
import HeaderButton from './HeaderButton';
|
||||||
import HeaderButtons from './HeaderButtons';
|
import HeaderButtons, {HEADER_KIND_GROUP} from './HeaderButtons';
|
||||||
import RightPanel from '../../structures/RightPanel';
|
import {RIGHT_PANEL_PHASES} from "../../../stores/RightPanelStorePhases";
|
||||||
|
|
||||||
const GROUP_PHASES = [
|
const GROUP_PHASES = [
|
||||||
RightPanel.Phase.GroupMemberInfo,
|
RIGHT_PANEL_PHASES.GroupMemberInfo,
|
||||||
RightPanel.Phase.GroupMemberList,
|
RIGHT_PANEL_PHASES.GroupMemberList,
|
||||||
];
|
];
|
||||||
const ROOM_PHASES = [
|
const ROOM_PHASES = [
|
||||||
RightPanel.Phase.GroupRoomList,
|
RIGHT_PANEL_PHASES.GroupRoomList,
|
||||||
RightPanel.Phase.GroupRoomInfo,
|
RIGHT_PANEL_PHASES.GroupRoomInfo,
|
||||||
];
|
];
|
||||||
|
|
||||||
export default class GroupHeaderButtons extends HeaderButtons {
|
export default class GroupHeaderButtons extends HeaderButtons {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props, RightPanel.Phase.GroupMemberList);
|
super(props, HEADER_KIND_GROUP);
|
||||||
this._onMembersClicked = this._onMembersClicked.bind(this);
|
this._onMembersClicked = this._onMembersClicked.bind(this);
|
||||||
this._onRoomsClicked = this._onRoomsClicked.bind(this);
|
this._onRoomsClicked = this._onRoomsClicked.bind(this);
|
||||||
}
|
}
|
||||||
|
@ -44,29 +45,31 @@ export default class GroupHeaderButtons extends HeaderButtons {
|
||||||
|
|
||||||
if (payload.action === "view_user") {
|
if (payload.action === "view_user") {
|
||||||
if (payload.member) {
|
if (payload.member) {
|
||||||
this.setPhase(RightPanel.Phase.RoomMemberInfo, {member: payload.member});
|
this.setPhase(RIGHT_PANEL_PHASES.RoomMemberInfo, {member: payload.member});
|
||||||
} else {
|
} else {
|
||||||
this.setPhase(RightPanel.Phase.GroupMemberList);
|
this.setPhase(RIGHT_PANEL_PHASES.GroupMemberList);
|
||||||
}
|
}
|
||||||
} else if (payload.action === "view_group") {
|
} else if (payload.action === "view_group") {
|
||||||
this.setPhase(RightPanel.Phase.GroupMemberList);
|
this.setPhase(RIGHT_PANEL_PHASES.GroupMemberList);
|
||||||
} else if (payload.action === "view_group_room") {
|
} else if (payload.action === "view_group_room") {
|
||||||
this.setPhase(RightPanel.Phase.GroupRoomInfo, {groupRoomId: payload.groupRoomId, groupId: payload.groupId});
|
this.setPhase(RIGHT_PANEL_PHASES.GroupRoomInfo, {groupRoomId: payload.groupRoomId, groupId: payload.groupId});
|
||||||
} else if (payload.action === "view_group_room_list") {
|
} else if (payload.action === "view_group_room_list") {
|
||||||
this.setPhase(RightPanel.Phase.GroupRoomList);
|
this.setPhase(RIGHT_PANEL_PHASES.GroupRoomList);
|
||||||
} else if (payload.action === "view_group_member_list") {
|
} else if (payload.action === "view_group_member_list") {
|
||||||
this.setPhase(RightPanel.Phase.GroupMemberList);
|
this.setPhase(RIGHT_PANEL_PHASES.GroupMemberList);
|
||||||
} else if (payload.action === "view_group_user") {
|
} else if (payload.action === "view_group_user") {
|
||||||
this.setPhase(RightPanel.Phase.GroupMemberInfo, {member: payload.member});
|
this.setPhase(RIGHT_PANEL_PHASES.GroupMemberInfo, {member: payload.member});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onMembersClicked() {
|
_onMembersClicked() {
|
||||||
this.togglePhase(RightPanel.Phase.GroupMemberList, GROUP_PHASES);
|
// This toggles for us, if needed
|
||||||
|
this.setPhase(RIGHT_PANEL_PHASES.GroupMemberList);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onRoomsClicked() {
|
_onRoomsClicked() {
|
||||||
this.togglePhase(RightPanel.Phase.GroupRoomList, ROOM_PHASES);
|
// This toggles for us, if needed
|
||||||
|
this.setPhase(RIGHT_PANEL_PHASES.GroupRoomList);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderButtons() {
|
renderButtons() {
|
||||||
|
|
|
@ -3,6 +3,7 @@ Copyright 2015, 2016 OpenMarket Ltd
|
||||||
Copyright 2017 Vector Creations Ltd
|
Copyright 2017 Vector Creations Ltd
|
||||||
Copyright 2017 New Vector Ltd
|
Copyright 2017 New Vector Ltd
|
||||||
Copyright 2018 New Vector Ltd
|
Copyright 2018 New Vector Ltd
|
||||||
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -18,62 +19,44 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import dis from '../../../dispatcher';
|
import dis from '../../../dispatcher';
|
||||||
|
import RightPanelStore from "../../../stores/RightPanelStore";
|
||||||
|
|
||||||
|
export const HEADER_KIND_ROOM = "room";
|
||||||
|
export const HEADER_KIND_GROUP = "group";
|
||||||
|
|
||||||
|
const HEADER_KINDS = [HEADER_KIND_GROUP, HEADER_KIND_ROOM];
|
||||||
|
|
||||||
export default class HeaderButtons extends React.Component {
|
export default class HeaderButtons extends React.Component {
|
||||||
constructor(props, initialPhase) {
|
constructor(props, kind) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
|
if (!HEADER_KINDS.includes(kind)) throw new Error(`Invalid header kind: ${kind}`);
|
||||||
|
|
||||||
|
const rps = RightPanelStore.getSharedInstance();
|
||||||
this.state = {
|
this.state = {
|
||||||
phase: props.collapsedRhs ? null : initialPhase,
|
headerKind: kind,
|
||||||
isUserPrivilegedInGroup: null,
|
phase: kind === HEADER_KIND_ROOM ? rps.visibleRoomPanelPhase : rps.visibleGroupPanelPhase,
|
||||||
};
|
};
|
||||||
this.onAction = this.onAction.bind(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
this.dispatcherRef = dis.register(this.onAction);
|
this._storeToken = RightPanelStore.getSharedInstance().addListener(this.onRightPanelUpdate.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
dis.unregister(this.dispatcherRef);
|
if (this._storeToken) this._storeToken.remove();
|
||||||
}
|
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
|
||||||
if (!prevProps.collapsedRhs && this.props.collapsedRhs) {
|
|
||||||
this.setState({
|
|
||||||
phase: null,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setPhase(phase, extras) {
|
setPhase(phase, extras) {
|
||||||
if (this.props.collapsedRhs) {
|
|
||||||
dis.dispatch({
|
dis.dispatch({
|
||||||
action: 'show_right_panel',
|
action: 'set_right_panel_phase',
|
||||||
});
|
|
||||||
}
|
|
||||||
dis.dispatch(Object.assign({
|
|
||||||
action: 'view_right_panel_phase',
|
|
||||||
phase: phase,
|
phase: phase,
|
||||||
}, extras));
|
refireParams: extras,
|
||||||
}
|
|
||||||
|
|
||||||
togglePhase(phase, validPhases = [phase]) {
|
|
||||||
if (validPhases.includes(this.state.phase)) {
|
|
||||||
dis.dispatch({
|
|
||||||
action: 'hide_right_panel',
|
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
this.setPhase(phase);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isPhase(phases) {
|
isPhase(phases: string | string[]) {
|
||||||
if (this.props.collapsedRhs) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (Array.isArray(phases)) {
|
if (Array.isArray(phases)) {
|
||||||
return phases.includes(this.state.phase);
|
return phases.includes(this.state.phase);
|
||||||
} else {
|
} else {
|
||||||
|
@ -81,22 +64,19 @@ export default class HeaderButtons extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onAction(payload) {
|
onRightPanelUpdate() {
|
||||||
if (payload.action === "view_right_panel_phase") {
|
const rps = RightPanelStore.getSharedInstance();
|
||||||
this.setState({
|
if (this.state.headerKind === HEADER_KIND_ROOM) {
|
||||||
phase: payload.phase,
|
this.setState({phase: rps.visibleRoomPanelPhase});
|
||||||
});
|
} else if (this.state.head === HEADER_KIND_GROUP) {
|
||||||
|
this.setState({phase: rps.visibleGroupPanelPhase});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
// inline style as this will be swapped around in future commits
|
// inline style as this will be swapped around in future commits
|
||||||
return <div className="mx_HeaderButtons" role="tablist">
|
return <div className="mx_HeaderButtons" role="tablist">
|
||||||
{ this.renderButtons() }
|
{this.renderButtons()}
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HeaderButtons.propTypes = {
|
|
||||||
collapsedRhs: PropTypes.bool,
|
|
||||||
};
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ Copyright 2015, 2016 OpenMarket Ltd
|
||||||
Copyright 2017 Vector Creations Ltd
|
Copyright 2017 Vector Creations Ltd
|
||||||
Copyright 2017 New Vector Ltd
|
Copyright 2017 New Vector Ltd
|
||||||
Copyright 2018 New Vector Ltd
|
Copyright 2018 New Vector Ltd
|
||||||
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -20,18 +21,18 @@ limitations under the License.
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
import HeaderButton from './HeaderButton';
|
import HeaderButton from './HeaderButton';
|
||||||
import HeaderButtons from './HeaderButtons';
|
import HeaderButtons, {HEADER_KIND_ROOM} from './HeaderButtons';
|
||||||
import RightPanel from '../../structures/RightPanel';
|
import {RIGHT_PANEL_PHASES} from "../../../stores/RightPanelStorePhases";
|
||||||
|
|
||||||
const MEMBER_PHASES = [
|
const MEMBER_PHASES = [
|
||||||
RightPanel.Phase.RoomMemberList,
|
RIGHT_PANEL_PHASES.RoomMemberList,
|
||||||
RightPanel.Phase.RoomMemberInfo,
|
RIGHT_PANEL_PHASES.RoomMemberInfo,
|
||||||
RightPanel.Phase.Room3pidMemberInfo,
|
RIGHT_PANEL_PHASES.Room3pidMemberInfo,
|
||||||
];
|
];
|
||||||
|
|
||||||
export default class RoomHeaderButtons extends HeaderButtons {
|
export default class RoomHeaderButtons extends HeaderButtons {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props, RightPanel.Phase.RoomMemberList);
|
super(props, HEADER_KIND_ROOM);
|
||||||
this._onMembersClicked = this._onMembersClicked.bind(this);
|
this._onMembersClicked = this._onMembersClicked.bind(this);
|
||||||
this._onFilesClicked = this._onFilesClicked.bind(this);
|
this._onFilesClicked = this._onFilesClicked.bind(this);
|
||||||
this._onNotificationsClicked = this._onNotificationsClicked.bind(this);
|
this._onNotificationsClicked = this._onNotificationsClicked.bind(this);
|
||||||
|
@ -41,29 +42,32 @@ export default class RoomHeaderButtons extends HeaderButtons {
|
||||||
super.onAction(payload);
|
super.onAction(payload);
|
||||||
if (payload.action === "view_user") {
|
if (payload.action === "view_user") {
|
||||||
if (payload.member) {
|
if (payload.member) {
|
||||||
this.setPhase(RightPanel.Phase.RoomMemberInfo, {member: payload.member});
|
this.setPhase(RIGHT_PANEL_PHASES.RoomMemberInfo, {member: payload.member});
|
||||||
} else {
|
} else {
|
||||||
this.setPhase(RightPanel.Phase.RoomMemberList);
|
this.setPhase(RIGHT_PANEL_PHASES.RoomMemberList);
|
||||||
}
|
}
|
||||||
} else if (payload.action === "view_3pid_invite") {
|
} else if (payload.action === "view_3pid_invite") {
|
||||||
if (payload.event) {
|
if (payload.event) {
|
||||||
this.setPhase(RightPanel.Phase.Room3pidMemberInfo, {event: payload.event});
|
this.setPhase(RIGHT_PANEL_PHASES.Room3pidMemberInfo, {event: payload.event});
|
||||||
} else {
|
} else {
|
||||||
this.setPhase(RightPanel.Phase.RoomMemberList);
|
this.setPhase(RIGHT_PANEL_PHASES.RoomMemberList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onMembersClicked() {
|
_onMembersClicked() {
|
||||||
this.togglePhase(RightPanel.Phase.RoomMemberList, MEMBER_PHASES);
|
// This toggles for us, if needed
|
||||||
|
this.setPhase(RIGHT_PANEL_PHASES.RoomMemberList);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onFilesClicked() {
|
_onFilesClicked() {
|
||||||
this.togglePhase(RightPanel.Phase.FilePanel);
|
// This toggles for us, if needed
|
||||||
|
this.setPhase(RIGHT_PANEL_PHASES.FilePanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onNotificationsClicked() {
|
_onNotificationsClicked() {
|
||||||
this.togglePhase(RightPanel.Phase.NotificationPanel);
|
// This toggles for us, if needed
|
||||||
|
this.setPhase(RIGHT_PANEL_PHASES.NotificationPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderButtons() {
|
renderButtons() {
|
||||||
|
@ -76,13 +80,13 @@ export default class RoomHeaderButtons extends HeaderButtons {
|
||||||
/>,
|
/>,
|
||||||
<HeaderButton key="filesButton" name="filesButton"
|
<HeaderButton key="filesButton" name="filesButton"
|
||||||
title={_t('Files')}
|
title={_t('Files')}
|
||||||
isHighlighted={this.isPhase(RightPanel.Phase.FilePanel)}
|
isHighlighted={this.isPhase(RIGHT_PANEL_PHASES.FilePanel)}
|
||||||
onClick={this._onFilesClicked}
|
onClick={this._onFilesClicked}
|
||||||
analytics={['Right Panel', 'File List Button', 'click']}
|
analytics={['Right Panel', 'File List Button', 'click']}
|
||||||
/>,
|
/>,
|
||||||
<HeaderButton key="notifsButton" name="notifsButton"
|
<HeaderButton key="notifsButton" name="notifsButton"
|
||||||
title={_t('Notifications')}
|
title={_t('Notifications')}
|
||||||
isHighlighted={this.isPhase(RightPanel.Phase.NotificationPanel)}
|
isHighlighted={this.isPhase(RIGHT_PANEL_PHASES.NotificationPanel)}
|
||||||
onClick={this._onNotificationsClicked}
|
onClick={this._onNotificationsClicked}
|
||||||
analytics={['Right Panel', 'Notification List Button', 'click']}
|
analytics={['Right Panel', 'Notification List Button', 'click']}
|
||||||
/>,
|
/>,
|
||||||
|
|
|
@ -32,6 +32,16 @@ const INITIAL_STATE = {
|
||||||
|
|
||||||
const GROUP_PHASES = Object.keys(RIGHT_PANEL_PHASES).filter(k => k.startsWith("Group"));
|
const GROUP_PHASES = Object.keys(RIGHT_PANEL_PHASES).filter(k => k.startsWith("Group"));
|
||||||
|
|
||||||
|
// These are the phases that are safe to persist (the ones that don't require additional
|
||||||
|
// arguments, basically).
|
||||||
|
const PHASES_TO_PERSIST = [
|
||||||
|
RIGHT_PANEL_PHASES.NotificationPanel,
|
||||||
|
RIGHT_PANEL_PHASES.FilePanel,
|
||||||
|
RIGHT_PANEL_PHASES.RoomMemberList,
|
||||||
|
RIGHT_PANEL_PHASES.GroupMemberList,
|
||||||
|
RIGHT_PANEL_PHASES.GroupRoomList,
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class for tracking the state of the right panel between layouts and
|
* A class for tracking the state of the right panel between layouts and
|
||||||
* sessions.
|
* sessions.
|
||||||
|
@ -62,12 +72,47 @@ export default class RightPanelStore extends Store {
|
||||||
return this._state.lastGroupPhase;
|
return this._state.lastGroupPhase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get visibleRoomPanelPhase(): string {
|
||||||
|
return this.isOpenForRoom ? this.roomPanelPhase : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
get visibleGroupPanelPhase(): string {
|
||||||
|
return this.isOpenForGroup ? this.groupPanelPhase : null;
|
||||||
|
}
|
||||||
|
|
||||||
_setState(newState) {
|
_setState(newState) {
|
||||||
this._state = Object.assign(this._state, newState);
|
this._state = Object.assign(this._state, newState);
|
||||||
SettingsStore.setValue("showRightPanelInRoom", null, SettingLevel.DEVICE, this._state.showRoomPanel);
|
|
||||||
SettingsStore.setValue("showRightPanelInGroup", null, SettingLevel.DEVICE, this._state.showGroupPanel);
|
SettingsStore.setValue(
|
||||||
SettingsStore.setValue("lastRightPanelPhaseForRoom", null, SettingLevel.DEVICE, this._state.lastRoomPhase);
|
"showRightPanelInRoom",
|
||||||
SettingsStore.setValue("lastRightPanelPhaseForGroup", null, SettingLevel.DEVICE, this._state.lastGroupPhase);
|
null,
|
||||||
|
SettingLevel.DEVICE,
|
||||||
|
this._state.showRoomPanel,
|
||||||
|
);
|
||||||
|
SettingsStore.setValue(
|
||||||
|
"showRightPanelInGroup",
|
||||||
|
null,
|
||||||
|
SettingLevel.DEVICE,
|
||||||
|
this._state.showGroupPanel,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (PHASES_TO_PERSIST.includes(this._state.lastRoomPhase)) {
|
||||||
|
SettingsStore.setValue(
|
||||||
|
"lastRightPanelPhaseForRoom",
|
||||||
|
null,
|
||||||
|
SettingLevel.DEVICE,
|
||||||
|
this._state.lastRoomPhase,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (PHASES_TO_PERSIST.includes(this._state.lastGroupPhase)) {
|
||||||
|
SettingsStore.setValue(
|
||||||
|
"lastRightPanelPhaseForGroup",
|
||||||
|
null,
|
||||||
|
SettingLevel.DEVICE,
|
||||||
|
this._state.lastGroupPhase,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.__emitChange();
|
this.__emitChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,6 +146,13 @@ export default class RightPanelStore extends Store {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Let things like the member info panel actually open to the right member.
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'after_right_panel_phase_change',
|
||||||
|
phase: targetPhase,
|
||||||
|
...(payload.refireParams || {}),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static getSharedInstance(): RightPanelStore {
|
static getSharedInstance(): RightPanelStore {
|
||||||
|
|
Loading…
Reference in a new issue