Fix Encryption Panel close button clashing with Base Card
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
f945155d04
commit
c4ee8e4a6c
4 changed files with 52 additions and 28 deletions
|
@ -202,13 +202,19 @@ 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 &&
|
||||||
|
this.state.verificationRequest && this.state.verificationRequest.pending
|
||||||
|
) {
|
||||||
|
// When the user clicks close on the encryption panel cancel the pending request first if any
|
||||||
|
this.state.verificationRequest.cancel();
|
||||||
} else {
|
} else {
|
||||||
// Otherwise we have got our user from RoomViewStore which means we're being shown
|
// Otherwise we have got our user from RoomViewStore which means we're being shown
|
||||||
// within a room/group, so go back to the member panel if we were in the encryption panel,
|
// 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.
|
// 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.ViewUser,
|
||||||
member: this.state.phase === RightPanelPhases.EncryptionPanel ? this.state.member : null,
|
member: isEncryptionPhase ? this.state.member : null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,6 +31,7 @@ interface IProps {
|
||||||
className?: string;
|
className?: string;
|
||||||
withoutScrollContainer?: boolean;
|
withoutScrollContainer?: boolean;
|
||||||
previousPhase?: RightPanelPhases;
|
previousPhase?: RightPanelPhases;
|
||||||
|
closeLabel?: string;
|
||||||
onClose?(): void;
|
onClose?(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ export const Group: React.FC<IGroupProps> = ({ className, title, children }) =>
|
||||||
};
|
};
|
||||||
|
|
||||||
const BaseCard: React.FC<IProps> = ({
|
const BaseCard: React.FC<IProps> = ({
|
||||||
|
closeLabel,
|
||||||
onClose,
|
onClose,
|
||||||
className,
|
className,
|
||||||
header,
|
header,
|
||||||
|
@ -68,7 +70,11 @@ const BaseCard: React.FC<IProps> = ({
|
||||||
|
|
||||||
let closeButton;
|
let closeButton;
|
||||||
if (onClose) {
|
if (onClose) {
|
||||||
closeButton = <AccessibleButton className="mx_BaseCard_close" onClick={onClose} title={_t("Close")} />;
|
closeButton = <AccessibleButton
|
||||||
|
className="mx_BaseCard_close"
|
||||||
|
onClick={onClose}
|
||||||
|
title={closeLabel || _t("Close")}
|
||||||
|
/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!withoutScrollContainer) {
|
if (!withoutScrollContainer) {
|
||||||
|
|
|
@ -27,6 +27,9 @@ import * as sdk from "../../../index";
|
||||||
import {_t} from "../../../languageHandler";
|
import {_t} from "../../../languageHandler";
|
||||||
import {VerificationRequest} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
|
import {VerificationRequest} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
|
||||||
import {RoomMember} from "matrix-js-sdk/src/models/room-member";
|
import {RoomMember} from "matrix-js-sdk/src/models/room-member";
|
||||||
|
import dis from "../../../dispatcher/dispatcher";
|
||||||
|
import {Action} from "../../../dispatcher/actions";
|
||||||
|
import {RightPanelPhases} from "../../../stores/RightPanelStorePhases";
|
||||||
|
|
||||||
// cancellation codes which constitute a key mismatch
|
// cancellation codes which constitute a key mismatch
|
||||||
const MISMATCHES = ["m.key_mismatch", "m.user_error", "m.mismatched_sas"];
|
const MISMATCHES = ["m.key_mismatch", "m.user_error", "m.mismatched_sas"];
|
||||||
|
@ -42,7 +45,14 @@ interface IProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
const EncryptionPanel: React.FC<IProps> = (props: IProps) => {
|
const EncryptionPanel: React.FC<IProps> = (props: IProps) => {
|
||||||
const {verificationRequest, verificationRequestPromise, member, onClose, layout, isRoomEncrypted} = props;
|
const {
|
||||||
|
verificationRequest,
|
||||||
|
verificationRequestPromise,
|
||||||
|
member,
|
||||||
|
onClose,
|
||||||
|
layout,
|
||||||
|
isRoomEncrypted,
|
||||||
|
} = props;
|
||||||
const [request, setRequest] = useState(verificationRequest);
|
const [request, setRequest] = useState(verificationRequest);
|
||||||
// state to show a spinner immediately after clicking "start verification",
|
// state to show a spinner immediately after clicking "start verification",
|
||||||
// before we have a request
|
// before we have a request
|
||||||
|
@ -95,22 +105,6 @@ const EncryptionPanel: React.FC<IProps> = (props: IProps) => {
|
||||||
}, [onClose, request]);
|
}, [onClose, request]);
|
||||||
useEventEmitter(request, "change", changeHandler);
|
useEventEmitter(request, "change", changeHandler);
|
||||||
|
|
||||||
const onCancel = useCallback(function() {
|
|
||||||
if (request) {
|
|
||||||
request.cancel();
|
|
||||||
}
|
|
||||||
}, [request]);
|
|
||||||
|
|
||||||
let cancelButton: JSX.Element;
|
|
||||||
if (layout !== "dialog" && request && request.pending) {
|
|
||||||
const AccessibleButton = sdk.getComponent("elements.AccessibleButton");
|
|
||||||
cancelButton = (<AccessibleButton
|
|
||||||
className="mx_EncryptionPanel_cancel"
|
|
||||||
onClick={onCancel}
|
|
||||||
title={_t('Cancel')}
|
|
||||||
></AccessibleButton>);
|
|
||||||
}
|
|
||||||
|
|
||||||
const onStartVerification = useCallback(async () => {
|
const onStartVerification = useCallback(async () => {
|
||||||
setRequesting(true);
|
setRequesting(true);
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.get();
|
||||||
|
@ -118,7 +112,13 @@ const EncryptionPanel: React.FC<IProps> = (props: IProps) => {
|
||||||
const verificationRequest_ = await cli.requestVerificationDM(member.userId, roomId);
|
const verificationRequest_ = await cli.requestVerificationDM(member.userId, roomId);
|
||||||
setRequest(verificationRequest_);
|
setRequest(verificationRequest_);
|
||||||
setPhase(verificationRequest_.phase);
|
setPhase(verificationRequest_.phase);
|
||||||
}, [member.userId]);
|
// Notify the RightPanelStore about this
|
||||||
|
dis.dispatch({
|
||||||
|
action: Action.SetRightPanelPhase,
|
||||||
|
phase: RightPanelPhases.EncryptionPanel,
|
||||||
|
refireParams: { member, verificationRequest: verificationRequest_ },
|
||||||
|
});
|
||||||
|
}, [member]);
|
||||||
|
|
||||||
const requested =
|
const requested =
|
||||||
(!request && isRequesting) ||
|
(!request && isRequesting) ||
|
||||||
|
@ -128,8 +128,7 @@ const EncryptionPanel: React.FC<IProps> = (props: IProps) => {
|
||||||
member.userId === MatrixClientPeg.get().getUserId();
|
member.userId === MatrixClientPeg.get().getUserId();
|
||||||
if (!request || requested) {
|
if (!request || requested) {
|
||||||
const initiatedByMe = (!request && isRequesting) || (request && request.initiatedByMe);
|
const initiatedByMe = (!request && isRequesting) || (request && request.initiatedByMe);
|
||||||
return (<React.Fragment>
|
return (
|
||||||
{cancelButton}
|
|
||||||
<EncryptionInfo
|
<EncryptionInfo
|
||||||
isRoomEncrypted={isRoomEncrypted}
|
isRoomEncrypted={isRoomEncrypted}
|
||||||
onStartVerification={onStartVerification}
|
onStartVerification={onStartVerification}
|
||||||
|
@ -138,10 +137,9 @@ const EncryptionPanel: React.FC<IProps> = (props: IProps) => {
|
||||||
waitingForOtherParty={requested && initiatedByMe}
|
waitingForOtherParty={requested && initiatedByMe}
|
||||||
waitingForNetwork={requested && !initiatedByMe}
|
waitingForNetwork={requested && !initiatedByMe}
|
||||||
inDialog={layout === "dialog"} />
|
inDialog={layout === "dialog"} />
|
||||||
</React.Fragment>);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (<React.Fragment>
|
return (
|
||||||
{cancelButton}
|
|
||||||
<VerificationPanel
|
<VerificationPanel
|
||||||
isRoomEncrypted={isRoomEncrypted}
|
isRoomEncrypted={isRoomEncrypted}
|
||||||
layout={layout}
|
layout={layout}
|
||||||
|
@ -152,7 +150,7 @@ const EncryptionPanel: React.FC<IProps> = (props: IProps) => {
|
||||||
inDialog={layout === "dialog"}
|
inDialog={layout === "dialog"}
|
||||||
phase={phase}
|
phase={phase}
|
||||||
/>
|
/>
|
||||||
</React.Fragment>);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1604,8 +1604,22 @@ const UserInfo: React.FC<Props> = ({
|
||||||
previousPhase = RightPanelPhases.RoomMemberList;
|
previousPhase = RightPanelPhases.RoomMemberList;
|
||||||
}
|
}
|
||||||
|
|
||||||
const header = <UserInfoHeader member={member} e2eStatus={e2eStatus} onClose={onClose} />;
|
let closeLabel = undefined;
|
||||||
return <BaseCard className={classes.join(" ")} header={header} onClose={onClose} previousPhase={previousPhase}>
|
if (phase === RightPanelPhases.EncryptionPanel) {
|
||||||
|
const verificationRequest = (props as React.ComponentProps<typeof EncryptionPanel>).verificationRequest;
|
||||||
|
if (verificationRequest && verificationRequest.pending) {
|
||||||
|
closeLabel = _t("Cancel");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const header = <UserInfoHeader member={member} e2eStatus={e2eStatus} />;
|
||||||
|
return <BaseCard
|
||||||
|
className={classes.join(" ")}
|
||||||
|
header={header}
|
||||||
|
onClose={onClose}
|
||||||
|
closeLabel={closeLabel}
|
||||||
|
previousPhase={previousPhase}
|
||||||
|
>
|
||||||
{ content }
|
{ content }
|
||||||
</BaseCard>;
|
</BaseCard>;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue