Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

MessageRecipient.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // @flow
  2. import React from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import { Icon, IconCloseCircle } from '../../../base/icons';
  5. import { connect } from '../../../base/redux';
  6. import AbstractMessageRecipient, {
  7. type Props,
  8. _mapDispatchToProps,
  9. _mapStateToProps
  10. } from '../AbstractMessageRecipient';
  11. /**
  12. * Class to implement the displaying of the recipient of the next message.
  13. */
  14. class MessageRecipient extends AbstractMessageRecipient<Props> {
  15. /**
  16. * Initializes a new {@code MessageRecipient} instance.
  17. *
  18. * @param {*} props - The read-only properties with which the new instance
  19. * is to be initialized.
  20. */
  21. constructor(props) {
  22. super(props);
  23. // Bind event handler so it is only bound once for every instance.
  24. this._onKeyPress = this._onKeyPress.bind(this);
  25. }
  26. _onKeyPress: (Object) => void;
  27. /**
  28. * KeyPress handler for accessibility.
  29. *
  30. * @param {Object} e - The key event to handle.
  31. *
  32. * @returns {void}
  33. */
  34. _onKeyPress(e) {
  35. if (
  36. (this.props._onRemovePrivateMessageRecipient || this.props._onHideLobbyChatRecipient)
  37. && (e.key === ' ' || e.key === 'Enter')
  38. ) {
  39. e.preventDefault();
  40. if (this.props._isLobbyChatActive && this.props._onHideLobbyChatRecipient) {
  41. this.props._onHideLobbyChatRecipient();
  42. } else if (this.props._onRemovePrivateMessageRecipient) {
  43. this.props._onRemovePrivateMessageRecipient();
  44. }
  45. }
  46. }
  47. /**
  48. * Implements {@code PureComponent#render}.
  49. *
  50. * @inheritdoc
  51. */
  52. render() {
  53. const { _privateMessageRecipient, _isLobbyChatActive,
  54. _lobbyMessageRecipient, _visible } = this.props;
  55. if ((!_privateMessageRecipient && !_isLobbyChatActive) || !_visible) {
  56. return null;
  57. }
  58. const { t } = this.props;
  59. return (
  60. <div
  61. className = { _isLobbyChatActive ? 'lobby-chat-recipient' : '' }
  62. id = 'chat-recipient'
  63. role = 'alert'>
  64. <span>
  65. { t(_isLobbyChatActive ? 'chat.lobbyChatMessageTo' : 'chat.messageTo', {
  66. recipient: _isLobbyChatActive ? _lobbyMessageRecipient : _privateMessageRecipient
  67. }) }
  68. </span>
  69. <div
  70. aria-label = { t('dialog.close') }
  71. onClick = { _isLobbyChatActive
  72. ? this.props._onHideLobbyChatRecipient : this.props._onRemovePrivateMessageRecipient }
  73. onKeyPress = { this._onKeyPress }
  74. role = 'button'
  75. tabIndex = { 0 }>
  76. <Icon
  77. src = { IconCloseCircle } />
  78. </div>
  79. </div>
  80. );
  81. }
  82. }
  83. export default translate(connect(_mapStateToProps, _mapDispatchToProps)(MessageRecipient));