Merge pull request #5598 from SimonBrandner/fix-confusing-right-panel

Fix confusing right panel button behaviour
This commit is contained in:
J. Ryan Stinnett 2021-02-04 16:30:41 +00:00 committed by GitHub
commit 4a73f3c504
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 26 deletions

View file

@ -30,7 +30,6 @@ import MatrixClientContext from "../../contexts/MatrixClientContext";
import {Action} from "../../dispatcher/actions"; import {Action} from "../../dispatcher/actions";
import RoomSummaryCard from "../views/right_panel/RoomSummaryCard"; import RoomSummaryCard from "../views/right_panel/RoomSummaryCard";
import WidgetCard from "../views/right_panel/WidgetCard"; import WidgetCard from "../views/right_panel/WidgetCard";
import defaultDispatcher from "../../dispatcher/dispatcher";
export default class RightPanel extends React.Component { export default class RightPanel extends React.Component {
static get propTypes() { static get propTypes() {
@ -186,7 +185,7 @@ export default class RightPanel extends React.Component {
} }
} }
onCloseUserInfo = () => { onClose = () => {
// XXX: There are three different ways of 'closing' this panel depending on what state // XXX: There are three different ways of 'closing' this panel depending on what state
// things are in... this knows far more than it should do about the state of the rest // things are in... this knows far more than it should do about the state of the rest
// of the app and is generally a bit silly. // of the app and is generally a bit silly.
@ -198,31 +197,21 @@ export default class RightPanel extends React.Component {
dis.dispatch({ dis.dispatch({
action: "view_home_page", action: "view_home_page",
}); });
} else if (this.state.phase === RightPanelPhases.EncryptionPanel && } else if (
this.state.phase === RightPanelPhases.EncryptionPanel &&
this.state.verificationRequest && this.state.verificationRequest.pending this.state.verificationRequest && this.state.verificationRequest.pending
) { ) {
// When the user clicks close on the encryption panel cancel the pending request first if any // When the user clicks close on the encryption panel cancel the pending request first if any
this.state.verificationRequest.cancel(); this.state.verificationRequest.cancel();
} else { } else {
// Otherwise we have got our user from RoomViewStore which means we're being shown // the RightPanelStore has no way of knowing which mode room/group it is in, so we handle closing here
// within a room/group, so go back to the member panel if we were in the encryption panel,
// or the member list if we were in the member panel... phew.
const isEncryptionPhase = this.state.phase === RightPanelPhases.EncryptionPanel;
dis.dispatch({ dis.dispatch({
action: Action.ViewUser, action: Action.ToggleRightPanel,
member: isEncryptionPhase ? this.state.member : null, type: this.props.groupId ? "group" : "room",
}); });
} }
}; };
onClose = () => {
// the RightPanelStore has no way of knowing which mode room/group it is in, so we handle closing here
defaultDispatcher.dispatch({
action: Action.ToggleRightPanel,
type: this.props.groupId ? "group" : "room",
});
};
render() { render() {
const MemberList = sdk.getComponent('rooms.MemberList'); const MemberList = sdk.getComponent('rooms.MemberList');
const UserInfo = sdk.getComponent('right_panel.UserInfo'); const UserInfo = sdk.getComponent('right_panel.UserInfo');
@ -260,7 +249,7 @@ export default class RightPanel extends React.Component {
user={this.state.member} user={this.state.member}
room={this.props.room} room={this.props.room}
key={roomId || this.state.member.userId} key={roomId || this.state.member.userId}
onClose={this.onCloseUserInfo} onClose={this.onClose}
phase={this.state.phase} phase={this.state.phase}
verificationRequest={this.state.verificationRequest} verificationRequest={this.state.verificationRequest}
verificationRequestPromise={this.state.verificationRequestPromise} verificationRequestPromise={this.state.verificationRequestPromise}
@ -276,7 +265,7 @@ export default class RightPanel extends React.Component {
user={this.state.member} user={this.state.member}
groupId={this.props.groupId} groupId={this.props.groupId}
key={this.state.member.userId} key={this.state.member.userId}
onClose={this.onCloseUserInfo} />; onClose={this.onClose} />;
break; break;
case RightPanelPhases.GroupRoomInfo: case RightPanelPhases.GroupRoomInfo:

View file

@ -33,6 +33,7 @@ interface IProps {
previousPhase?: RightPanelPhases; previousPhase?: RightPanelPhases;
closeLabel?: string; closeLabel?: string;
onClose?(): void; onClose?(): void;
refireParams?;
} }
interface IGroupProps { interface IGroupProps {
@ -56,6 +57,7 @@ const BaseCard: React.FC<IProps> = ({
withoutScrollContainer, withoutScrollContainer,
previousPhase, previousPhase,
children, children,
refireParams,
}) => { }) => {
let backButton; let backButton;
if (previousPhase) { if (previousPhase) {
@ -63,6 +65,7 @@ const BaseCard: React.FC<IProps> = ({
defaultDispatcher.dispatch<SetRightPanelPhasePayload>({ defaultDispatcher.dispatch<SetRightPanelPhasePayload>({
action: Action.SetRightPanelPhase, action: Action.SetRightPanelPhase,
phase: previousPhase, phase: previousPhase,
refireParams: refireParams,
}); });
}; };
backButton = <AccessibleButton className="mx_BaseCard_back" onClick={onBackClick} title={_t("Back")} />; backButton = <AccessibleButton className="mx_BaseCard_back" onClick={onBackClick} title={_t("Back")} />;

View file

@ -60,6 +60,7 @@ import QuestionDialog from "../dialogs/QuestionDialog";
import ConfirmUserActionDialog from "../dialogs/ConfirmUserActionDialog"; import ConfirmUserActionDialog from "../dialogs/ConfirmUserActionDialog";
import InfoDialog from "../dialogs/InfoDialog"; import InfoDialog from "../dialogs/InfoDialog";
import { EventType } from "matrix-js-sdk/src/@types/event"; import { EventType } from "matrix-js-sdk/src/@types/event";
import {SetRightPanelPhasePayload} from "../../../dispatcher/payloads/SetRightPanelPhasePayload";
interface IDevice { interface IDevice {
deviceId: string; deviceId: string;
@ -1534,6 +1535,24 @@ const UserInfo: React.FC<Props> = ({
const classes = ["mx_UserInfo"]; const classes = ["mx_UserInfo"];
let refireParams;
let previousPhase: RightPanelPhases;
// We have no previousPhase for when viewing a UserInfo from a Group or without a Room at this time
if (room && phase === RightPanelPhases.EncryptionPanel) {
previousPhase = RightPanelPhases.RoomMemberInfo;
refireParams = {member: member};
} else if (room) {
previousPhase = RightPanelPhases.RoomMemberList;
}
const onEncryptionPanelClose = () => {
dis.dispatch<SetRightPanelPhasePayload>({
action: Action.SetRightPanelPhase,
phase: previousPhase,
refireParams: refireParams,
});
}
let content; let content;
switch (phase) { switch (phase) {
case RightPanelPhases.RoomMemberInfo: case RightPanelPhases.RoomMemberInfo:
@ -1553,19 +1572,13 @@ const UserInfo: React.FC<Props> = ({
<EncryptionPanel <EncryptionPanel
{...props as React.ComponentProps<typeof EncryptionPanel>} {...props as React.ComponentProps<typeof EncryptionPanel>}
member={member} member={member}
onClose={onClose} onClose={onEncryptionPanelClose}
isRoomEncrypted={isRoomEncrypted} isRoomEncrypted={isRoomEncrypted}
/> />
); );
break; break;
} }
let previousPhase: RightPanelPhases;
// We have no previousPhase for when viewing a UserInfo from a Group or without a Room at this time
if (room) {
previousPhase = RightPanelPhases.RoomMemberList;
}
let closeLabel = undefined; let closeLabel = undefined;
if (phase === RightPanelPhases.EncryptionPanel) { if (phase === RightPanelPhases.EncryptionPanel) {
const verificationRequest = (props as React.ComponentProps<typeof EncryptionPanel>).verificationRequest; const verificationRequest = (props as React.ComponentProps<typeof EncryptionPanel>).verificationRequest;
@ -1581,6 +1594,7 @@ const UserInfo: React.FC<Props> = ({
onClose={onClose} onClose={onClose}
closeLabel={closeLabel} closeLabel={closeLabel}
previousPhase={previousPhase} previousPhase={previousPhase}
refireParams={refireParams}
> >
{ content } { content }
</BaseCard>; </BaseCard>;