2019-10-07 12:35:04 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import { translate } from '../../../base/i18n';
|
|
|
|
import { Icon, IconCancelSelection } from '../../../base/icons';
|
|
|
|
import { connect } from '../../../base/redux';
|
|
|
|
import AbstractMessageRecipient, {
|
|
|
|
_mapDispatchToProps,
|
2019-10-15 14:08:23 +00:00
|
|
|
_mapStateToProps,
|
|
|
|
type Props
|
2019-10-07 12:35:04 +00:00
|
|
|
} from '../AbstractMessageRecipient';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class to implement the displaying of the recipient of the next message.
|
|
|
|
*/
|
2019-10-15 14:08:23 +00:00
|
|
|
class MessageRecipient extends AbstractMessageRecipient<Props> {
|
2021-06-10 12:48:44 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code MessageRecipient} instance.
|
|
|
|
*
|
|
|
|
* @param {*} props - The read-only properties with which the new instance
|
|
|
|
* is to be initialized.
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handler so it is only bound once for every instance.
|
|
|
|
this._onKeyPress = this._onKeyPress.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onKeyPress: (Object) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* KeyPress handler for accessibility.
|
|
|
|
*
|
|
|
|
* @param {Object} e - The key event to handle.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onKeyPress(e) {
|
2022-03-03 17:29:38 +00:00
|
|
|
if (
|
|
|
|
(this.props._onRemovePrivateMessageRecipient || this.props._onHideLobbyChatRecipient)
|
|
|
|
&& (e.key === ' ' || e.key === 'Enter')
|
|
|
|
) {
|
2021-06-10 12:48:44 +00:00
|
|
|
e.preventDefault();
|
2022-03-03 17:29:38 +00:00
|
|
|
if (this.props._isLobbyChatActive && this.props._onHideLobbyChatRecipient) {
|
|
|
|
this.props._onHideLobbyChatRecipient();
|
|
|
|
} else if (this.props._onRemovePrivateMessageRecipient) {
|
|
|
|
this.props._onRemovePrivateMessageRecipient();
|
|
|
|
}
|
2021-06-10 12:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 12:35:04 +00:00
|
|
|
/**
|
|
|
|
* Implements {@code PureComponent#render}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
2022-03-03 17:29:38 +00:00
|
|
|
const { _privateMessageRecipient, _isLobbyChatActive,
|
|
|
|
_lobbyMessageRecipient, _visible } = this.props;
|
2019-10-07 12:35:04 +00:00
|
|
|
|
2022-03-03 17:29:38 +00:00
|
|
|
if ((!_privateMessageRecipient && !_isLobbyChatActive) || !_visible) {
|
2019-10-07 12:35:04 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { t } = this.props;
|
|
|
|
|
|
|
|
return (
|
2021-06-10 12:48:44 +00:00
|
|
|
<div
|
2022-03-03 17:29:38 +00:00
|
|
|
className = { _isLobbyChatActive ? 'lobby-chat-recipient' : '' }
|
2021-06-10 12:48:44 +00:00
|
|
|
id = 'chat-recipient'
|
|
|
|
role = 'alert'>
|
2019-10-07 12:35:04 +00:00
|
|
|
<span>
|
2022-03-03 17:29:38 +00:00
|
|
|
{ t(_isLobbyChatActive ? 'chat.lobbyChatMessageTo' : 'chat.messageTo', {
|
|
|
|
recipient: _isLobbyChatActive ? _lobbyMessageRecipient : _privateMessageRecipient
|
2019-10-07 12:35:04 +00:00
|
|
|
}) }
|
|
|
|
</span>
|
2021-06-10 12:48:44 +00:00
|
|
|
<div
|
|
|
|
aria-label = { t('dialog.close') }
|
2022-03-03 17:29:38 +00:00
|
|
|
onClick = { _isLobbyChatActive
|
|
|
|
? this.props._onHideLobbyChatRecipient : this.props._onRemovePrivateMessageRecipient }
|
2021-06-10 12:48:44 +00:00
|
|
|
onKeyPress = { this._onKeyPress }
|
|
|
|
role = 'button'
|
|
|
|
tabIndex = { 0 }>
|
2019-10-07 12:35:04 +00:00
|
|
|
<Icon
|
|
|
|
src = { IconCancelSelection } />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(_mapStateToProps, _mapDispatchToProps)(MessageRecipient));
|