Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SecondaryToolbar.web.js 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import { FeedbackButton } from '../../feedback';
  5. import UIEvents from '../../../../service/UI/UIEvents';
  6. import {
  7. changeLocalRaiseHand,
  8. setProfileButtonUnclickable,
  9. showRecordingButton,
  10. toggleSideToolbarContainer
  11. } from '../actions';
  12. import Toolbar from './Toolbar';
  13. import { getToolbarClassNames } from '../functions';
  14. declare var APP: Object;
  15. declare var config: Object;
  16. /**
  17. * Implementation of secondary toolbar React component.
  18. *
  19. * @class SecondaryToolbar
  20. * @extends Component
  21. */
  22. class SecondaryToolbar extends Component {
  23. state: Object;
  24. /**
  25. * Secondary toolbar property types.
  26. *
  27. * @static
  28. */
  29. static propTypes = {
  30. /**
  31. * Handler dispatching local "Raise hand".
  32. */
  33. _onLocalRaiseHandChanged: React.PropTypes.func,
  34. /**
  35. * Handler setting profile button unclickable.
  36. */
  37. _onSetProfileButtonUnclickable: React.PropTypes.func,
  38. /**
  39. * Handler for showing recording button.
  40. */
  41. _onShowRecordingButton: React.PropTypes.func,
  42. /**
  43. * Handler dispatching toggle toolbar container.
  44. */
  45. _onSideToolbarContainerToggled: React.PropTypes.func,
  46. /**
  47. * Contains map of secondary toolbar buttons.
  48. */
  49. _secondaryToolbarButtons: React.PropTypes.instanceOf(Map),
  50. /**
  51. * Shows whether toolbox is visible.
  52. */
  53. _visible: React.PropTypes.bool
  54. };
  55. /**
  56. * Constructs instance of SecondaryToolbar component.
  57. *
  58. * @param {Object} props - React component properties.
  59. */
  60. constructor(props) {
  61. super(props);
  62. const buttonHandlers = {
  63. /**
  64. * Mount handler for profile button.
  65. *
  66. * @type {Object}
  67. */
  68. profile: {
  69. onMount: () => {
  70. APP.tokenData.isGuest
  71. || this.props._onSetProfileButtonUnclickable(true);
  72. }
  73. },
  74. /**
  75. * Mount/Unmount handlers for raisehand button.
  76. *
  77. * @type {button}
  78. */
  79. raisehand: {
  80. onMount: () => {
  81. APP.UI.addListener(UIEvents.LOCAL_RAISE_HAND_CHANGED,
  82. this.props._onLocalRaiseHandChanged);
  83. },
  84. onUnmount: () => {
  85. APP.UI.removeListener(UIEvents.LOCAL_RAISE_HAND_CHANGED,
  86. this.props._onLocalRaiseHandChanged);
  87. }
  88. },
  89. /**
  90. * Mount handler for recording button.
  91. *
  92. * @type {Object}
  93. */
  94. recording: {
  95. onMount: () => {
  96. if (config.enableRecording) {
  97. this.props._onShowRecordingButton();
  98. }
  99. }
  100. }
  101. };
  102. this.state = {
  103. /**
  104. * Object containing on mount/unmount handlers for toolbar buttons.
  105. *
  106. * @type {Object}
  107. */
  108. buttonHandlers
  109. };
  110. }
  111. /**
  112. * Register legacy UI listener.
  113. *
  114. * @returns {void}
  115. */
  116. componentDidMount(): void {
  117. APP.UI.addListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  118. this.props._onSideToolbarContainerToggled);
  119. }
  120. /**
  121. * Unregisters legacy UI listener.
  122. *
  123. * @returns {void}
  124. */
  125. componentWillUnmount(): void {
  126. APP.UI.removeListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  127. this.props._onSideToolbarContainerToggled);
  128. }
  129. /**
  130. * Renders secondary toolbar component.
  131. *
  132. * @returns {ReactElement}
  133. */
  134. render(): ReactElement<*> {
  135. const { buttonHandlers } = this.state;
  136. const { _secondaryToolbarButtons } = this.props;
  137. const { secondaryToolbarClassName } = getToolbarClassNames(this.props);
  138. return (
  139. <Toolbar
  140. buttonHandlers = { buttonHandlers }
  141. className = { secondaryToolbarClassName }
  142. toolbarButtons = { _secondaryToolbarButtons }>
  143. <FeedbackButton />
  144. </Toolbar>
  145. );
  146. }
  147. }
  148. /**
  149. * Maps some of Redux actions to component's props.
  150. *
  151. * @param {Function} dispatch - Redux action dispatcher.
  152. * @returns {{
  153. * _onLocalRaiseHandChanged: Function,
  154. * _onSetProfileButtonUnclickable: Function,
  155. * _onShowRecordingButton: Function,
  156. * _onSideToolbarContainerToggled
  157. * }}
  158. * @private
  159. */
  160. function _mapDispatchToProps(dispatch: Function): Object {
  161. return {
  162. /**
  163. * Dispatches an action that 'hand' is raised.
  164. *
  165. * @param {boolean} isRaisedHand - Show whether hand is raised.
  166. * @returns {Object} Dispatched action.
  167. */
  168. _onLocalRaiseHandChanged(isRaisedHand: boolean) {
  169. return dispatch(changeLocalRaiseHand(isRaisedHand));
  170. },
  171. /**
  172. * Dispatches an action signalling to set profile button unclickable.
  173. *
  174. * @param {boolean} unclickable - Flag showing whether unclickable
  175. * property is true.
  176. * @returns {Object} Dispatched action.
  177. */
  178. _onSetProfileButtonUnclickable(unclickable: boolean) {
  179. return dispatch(setProfileButtonUnclickable(unclickable));
  180. },
  181. /**
  182. * Dispatches an action signalling that recording button should be
  183. * shown.
  184. *
  185. * @returns {Object} Dispatched action.
  186. */
  187. _onShowRecordingButton() {
  188. return dispatch(showRecordingButton());
  189. },
  190. /**
  191. * Dispatches an action signalling that side toolbar container is
  192. * toggled.
  193. *
  194. * @param {string} containerId - Id of side toolbar container.
  195. * @returns {Object} Dispatched action.
  196. */
  197. _onSideToolbarContainerToggled(containerId: string) {
  198. return dispatch(toggleSideToolbarContainer(containerId));
  199. }
  200. };
  201. }
  202. /**
  203. * Maps part of Redux state to component's props.
  204. *
  205. * @param {Object} state - Snapshot of Redux store.
  206. * @returns {{
  207. * _secondaryToolbarButtons: Map,
  208. * _visible: boolean
  209. * }}
  210. * @private
  211. */
  212. function _mapStateToProps(state: Object): Object {
  213. const {
  214. secondaryToolbarButtons,
  215. visible
  216. } = state['features/toolbox'];
  217. return {
  218. /**
  219. * Default toolbar buttons for secondary toolbar.
  220. *
  221. * @protected
  222. * @type {Map}
  223. */
  224. _secondaryToolbarButtons: secondaryToolbarButtons,
  225. /**
  226. * Shows whether toolbar is visible.
  227. *
  228. * @protected
  229. * @type {boolean}
  230. */
  231. _visible: visible
  232. };
  233. }
  234. export default connect(_mapStateToProps, _mapDispatchToProps)(SecondaryToolbar);