Merge pull request #4233 from matrix-org/t3chguy/invite_fixes

Invite Dialog fixes
This commit is contained in:
Michael Telatynski 2020-03-19 17:32:30 +00:00 committed by GitHub
commit c616107d1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 21 deletions

View file

@ -35,6 +35,7 @@ import createRoom, {canEncryptToAllUsers} from "../../../createRoom";
import {inviteMultipleToRoom} from "../../../RoomInvite"; import {inviteMultipleToRoom} from "../../../RoomInvite";
import SettingsStore from '../../../settings/SettingsStore'; import SettingsStore from '../../../settings/SettingsStore';
import RoomListStore, {TAG_DM} from "../../../stores/RoomListStore"; import RoomListStore, {TAG_DM} from "../../../stores/RoomListStore";
import {Key} from "../../../Keyboard";
export const KIND_DM = "dm"; export const KIND_DM = "dm";
export const KIND_INVITE = "invite"; export const KIND_INVITE = "invite";
@ -125,7 +126,7 @@ class ThreepidMember extends Member {
class DMUserTile extends React.PureComponent { class DMUserTile extends React.PureComponent {
static propTypes = { static propTypes = {
member: PropTypes.object.isRequired, // Should be a Member (see interface above) member: PropTypes.object.isRequired, // Should be a Member (see interface above)
onRemove: PropTypes.func.isRequired, // takes 1 argument, the member being removed onRemove: PropTypes.func, // takes 1 argument, the member being removed
}; };
_onRemove = (e) => { _onRemove = (e) => {
@ -156,18 +157,25 @@ class DMUserTile extends React.PureComponent {
width={avatarSize} width={avatarSize}
height={avatarSize} />; height={avatarSize} />;
return ( let closeButton;
<span className='mx_InviteDialog_userTile'> if (this.props.onRemove) {
<span className='mx_InviteDialog_userTile_pill'> closeButton = (
{avatar}
<span className='mx_InviteDialog_userTile_name'>{this.props.member.name}</span>
</span>
<AccessibleButton <AccessibleButton
className='mx_InviteDialog_userTile_remove' className='mx_InviteDialog_userTile_remove'
onClick={this._onRemove} onClick={this._onRemove}
> >
<img src={require("../../../../res/img/icon-pill-remove.svg")} alt={_t('Remove')} width={8} height={8} /> <img src={require("../../../../res/img/icon-pill-remove.svg")} alt={_t('Remove')} width={8} height={8} />
</AccessibleButton> </AccessibleButton>
);
}
return (
<span className='mx_InviteDialog_userTile'>
<span className='mx_InviteDialog_userTile_pill'>
{avatar}
<span className='mx_InviteDialog_userTile_name'>{this.props.member.name}</span>
</span>
{ closeButton }
</span> </span>
); );
} }
@ -640,11 +648,14 @@ export default class InviteDialog extends React.PureComponent {
}); });
}; };
_cancel = () => { _onKeyDown = (e) => {
// We do not want the user to close the dialog while an action is in progress // when the field is empty and the user hits backspace remove the right-most target
if (this.state.busy) return; if (!e.target.value && !this.state.busy && this.state.targets.length > 0 && e.key === Key.BACKSPACE &&
!e.ctrlKey && !e.shiftKey && !e.metaKey
this.props.onFinished(); ) {
e.preventDefault();
this._removeMember(this.state.targets[this.state.targets.length - 1]);
}
}; };
_updateFilter = (e) => { _updateFilter = (e) => {
@ -889,7 +900,7 @@ export default class InviteDialog extends React.PureComponent {
_onManageSettingsClick = (e) => { _onManageSettingsClick = (e) => {
e.preventDefault(); e.preventDefault();
dis.dispatch({ action: 'view_user_settings' }); dis.dispatch({ action: 'view_user_settings' });
this._cancel(); this.props.onFinished();
}; };
_renderSection(kind: "recents"|"suggestions") { _renderSection(kind: "recents"|"suggestions") {
@ -984,17 +995,18 @@ export default class InviteDialog extends React.PureComponent {
_renderEditor() { _renderEditor() {
const targets = this.state.targets.map(t => ( const targets = this.state.targets.map(t => (
<DMUserTile member={t} onRemove={this._removeMember} key={t.userId} /> <DMUserTile member={t} onRemove={!this.state.busy && this._removeMember} key={t.userId} />
)); ));
const input = ( const input = (
<textarea <textarea
key={"input"}
rows={1} rows={1}
onKeyDown={this._onKeyDown}
onChange={this._updateFilter} onChange={this._updateFilter}
value={this.state.filterText} value={this.state.filterText}
ref={this._editorRef} ref={this._editorRef}
onPaste={this._onPaste} onPaste={this._onPaste}
autoFocus={true} autoFocus={true}
disabled={this.state.busy}
/> />
); );
return ( return (
@ -1060,10 +1072,11 @@ export default class InviteDialog extends React.PureComponent {
title = _t("Direct Messages"); title = _t("Direct Messages");
helpText = _t( helpText = _t(
"If you can't find someone, ask them for their username, share your " + "Start a conversation with someone using their name, username (like <userId/>) or email address.",
"username (%(userId)s) or <a>profile link</a>.", {},
{userId}, {userId: () => {
{a: (sub) => <a href={makeUserPermalink(userId)} rel="noreferrer noopener" target="_blank">{sub}</a>}, return <a href={makeUserPermalink(userId)} rel="noreferrer noopener" target="_blank">{userId}</a>;
}},
); );
buttonText = _t("Go"); buttonText = _t("Go");
goButtonFn = this._startDm; goButtonFn = this._startDm;
@ -1087,7 +1100,7 @@ export default class InviteDialog extends React.PureComponent {
<BaseDialog <BaseDialog
className='mx_InviteDialog' className='mx_InviteDialog'
hasCancel={true} hasCancel={true}
onFinished={this._cancel} onFinished={this.props.onFinished}
title={title} title={title}
> >
<div className='mx_InviteDialog_content'> <div className='mx_InviteDialog_content'>

View file

@ -1585,7 +1585,7 @@
"Recent Conversations": "Recent Conversations", "Recent Conversations": "Recent Conversations",
"Suggestions": "Suggestions", "Suggestions": "Suggestions",
"Recently Direct Messaged": "Recently Direct Messaged", "Recently Direct Messaged": "Recently Direct Messaged",
"If you can't find someone, ask them for their username, share your username (%(userId)s) or <a>profile link</a>.": "If you can't find someone, ask them for their username, share your username (%(userId)s) or <a>profile link</a>.", "Start a conversation with someone using their name, username (like <userId/>) or email address.": "Start a conversation with someone using their name, username (like <userId/>) or email address.",
"Go": "Go", "Go": "Go",
"If you can't find someone, ask them for their username (e.g. @user:server.com) or <a>share this room</a>.": "If you can't find someone, ask them for their username (e.g. @user:server.com) or <a>share this room</a>.", "If you can't find someone, ask them for their username (e.g. @user:server.com) or <a>share this room</a>.": "If you can't find someone, ask them for their username (e.g. @user:server.com) or <a>share this room</a>.",
"You added a new session '%(displayName)s', which is requesting encryption keys.": "You added a new session '%(displayName)s', which is requesting encryption keys.", "You added a new session '%(displayName)s', which is requesting encryption keys.": "You added a new session '%(displayName)s', which is requesting encryption keys.",