選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ReactionsMenuButton.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // @flow
  2. import React, { useEffect } from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import { IconRaisedHand } from '../../../base/icons';
  5. import { getLocalParticipant } from '../../../base/participants';
  6. import { connect } from '../../../base/redux';
  7. import ToolbarButton from '../../../toolbox/components/web/ToolbarButton';
  8. import { sendReaction } from '../../actions.any';
  9. import { toggleReactionsMenuVisibility } from '../../actions.web';
  10. import { REACTIONS, type ReactionEmojiProps } from '../../constants';
  11. import { getReactionsQueue } from '../../functions.any';
  12. import { getReactionsMenuVisibility } from '../../functions.web';
  13. import ReactionEmoji from './ReactionEmoji';
  14. import ReactionsMenuPopup from './ReactionsMenuPopup';
  15. type Props = {
  16. /**
  17. * Used for translation.
  18. */
  19. t: Function,
  20. /**
  21. * Whether or not the local participant's hand is raised.
  22. */
  23. raisedHand: boolean,
  24. /**
  25. * Click handler for the reaction button. Toggles the reactions menu.
  26. */
  27. onReactionsClick: Function,
  28. /**
  29. * Whether or not the reactions menu is open.
  30. */
  31. isOpen: boolean,
  32. /**
  33. * The array of reactions to be displayed.
  34. */
  35. reactionsQueue: Array<ReactionEmojiProps>,
  36. /**
  37. * Redux dispatch function.
  38. */
  39. dispatch: Function
  40. };
  41. declare var APP: Object;
  42. /**
  43. * Button used for the reactions menu.
  44. *
  45. * @returns {ReactElement}
  46. */
  47. function ReactionsMenuButton({
  48. t,
  49. raisedHand,
  50. isOpen,
  51. reactionsQueue,
  52. dispatch
  53. }: Props) {
  54. useEffect(() => {
  55. const KEYBOARD_SHORTCUTS = Object.keys(REACTIONS).map(key => {
  56. return {
  57. character: REACTIONS[key].shortcutChar,
  58. exec: () => dispatch(sendReaction(key)),
  59. helpDescription: t(`toolbar.reaction${key.charAt(0).toUpperCase()}${key.slice(1)}`),
  60. altKey: true
  61. };
  62. });
  63. KEYBOARD_SHORTCUTS.forEach(shortcut => {
  64. APP.keyboardshortcut.registerShortcut(
  65. shortcut.character,
  66. null,
  67. shortcut.exec,
  68. shortcut.helpDescription,
  69. shortcut.altKey);
  70. });
  71. return () => {
  72. Object.keys(REACTIONS).map(key => REACTIONS[key].shortcutChar)
  73. .forEach(letter =>
  74. APP.keyboardshortcut.unregisterShortcut(letter, true));
  75. };
  76. }, []);
  77. /**
  78. * Toggles the reactions menu visibility.
  79. *
  80. * @returns {void}
  81. */
  82. function toggleReactionsMenu() {
  83. dispatch(toggleReactionsMenuVisibility());
  84. }
  85. return (
  86. <div className = 'reactions-menu-popup-container'>
  87. <ReactionsMenuPopup>
  88. <ToolbarButton
  89. accessibilityLabel = { t('toolbar.accessibilityLabel.reactionsMenu') }
  90. icon = { IconRaisedHand }
  91. key = 'reactions'
  92. onClick = { toggleReactionsMenu }
  93. toggled = { raisedHand }
  94. tooltip = { t(`toolbar.${isOpen ? 'closeReactionsMenu' : 'openReactionsMenu'}`) } />
  95. </ReactionsMenuPopup>
  96. {reactionsQueue.map(({ reaction, uid }, index) => (<ReactionEmoji
  97. index = { index }
  98. key = { uid }
  99. reaction = { reaction }
  100. uid = { uid } />))}
  101. </div>
  102. );
  103. }
  104. /**
  105. * Function that maps parts of Redux state tree into component props.
  106. *
  107. * @param {Object} state - Redux state.
  108. * @returns {Object}
  109. */
  110. function mapStateToProps(state) {
  111. const localParticipant = getLocalParticipant(state);
  112. return {
  113. isOpen: getReactionsMenuVisibility(state),
  114. reactionsQueue: getReactionsQueue(state),
  115. raisedHand: localParticipant?.raisedHand
  116. };
  117. }
  118. export default translate(connect(mapStateToProps)(ReactionsMenuButton));