You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reducer.js 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /* @flow */
  2. import { ReducerRegistry } from '../base/redux';
  3. import {
  4. CLEAR_TOOLBOX_TIMEOUT,
  5. SET_DEFAULT_TOOLBOX_BUTTONS,
  6. SET_SUBJECT,
  7. SET_SUBJECT_SLIDE_IN,
  8. SET_TOOLBAR_BUTTON,
  9. SET_TOOLBAR_HOVERED,
  10. SET_TOOLBOX_ALWAYS_VISIBLE,
  11. SET_TOOLBOX_ENABLED,
  12. SET_TOOLBOX_TIMEOUT,
  13. SET_TOOLBOX_TIMEOUT_MS,
  14. SET_TOOLBOX_VISIBLE
  15. } from './actionTypes';
  16. import defaultToolbarButtons from './defaultToolbarButtons';
  17. declare var interfaceConfig: Object;
  18. /**
  19. * Returns initial state for toolbox's part of Redux store.
  20. *
  21. * @private
  22. * @returns {{
  23. * alwaysVisible: boolean,
  24. * hovered: boolean,
  25. * primaryToolbarButtons: Map,
  26. * secondaryToolbarButtons: Map,
  27. * subject: string,
  28. * subjectSlideIn: boolean,
  29. * timeoutID: number,
  30. * timeoutMS: number,
  31. * visible: boolean
  32. * }}
  33. */
  34. function _getInitialState() {
  35. // Default toolbox timeout for mobile app.
  36. let timeoutMS = 5000;
  37. if (typeof interfaceConfig !== 'undefined'
  38. && interfaceConfig.INITIAL_TOOLBAR_TIMEOUT) {
  39. timeoutMS = interfaceConfig.INITIAL_TOOLBAR_TIMEOUT;
  40. }
  41. return {
  42. /**
  43. * The indicator which determines whether the Toolbox should always be
  44. * visible.
  45. *
  46. * @type {boolean}
  47. */
  48. alwaysVisible: false,
  49. /**
  50. * The indicator which determines whether the Toolbox is enabled. For
  51. * example, modules/UI/recording/Recording.js disables the Toolbox.
  52. *
  53. * @type {boolean}
  54. */
  55. enabled: true,
  56. /**
  57. * The indicator which determines whether a Toolbar in the Toolbox is
  58. * hovered.
  59. *
  60. * @type {boolean}
  61. */
  62. hovered: false,
  63. /**
  64. * A Map of the default buttons of the PrimaryToolbar.
  65. *
  66. * @type {Map}
  67. */
  68. primaryToolbarButtons: new Map(),
  69. /**
  70. * A Map of the default buttons of the SecondaryToolbar.
  71. *
  72. * @type {Map}
  73. */
  74. secondaryToolbarButtons: new Map(),
  75. /**
  76. * The text of the conference subject.
  77. *
  78. * @type {string}
  79. */
  80. subject: '',
  81. /**
  82. * The indicator which determines whether the subject is sliding in.
  83. *
  84. * @type {boolean}
  85. */
  86. subjectSlideIn: false,
  87. /**
  88. * A number, non-zero value which identifies the timer created by a call
  89. * to setTimeout() with timeoutMS.
  90. *
  91. * @type {number|null}
  92. */
  93. timeoutID: null,
  94. /**
  95. * The delay in milliseconds before timeoutID executes (after its
  96. * initialization).
  97. *
  98. * @type {number}
  99. */
  100. timeoutMS,
  101. /**
  102. * The indicator which determines whether the Toolbox is visible.
  103. *
  104. * @type {boolean}
  105. */
  106. visible: false
  107. };
  108. }
  109. ReducerRegistry.register(
  110. 'features/toolbox',
  111. (state: Object = _getInitialState(), action: Object) => {
  112. switch (action.type) {
  113. case CLEAR_TOOLBOX_TIMEOUT:
  114. return {
  115. ...state,
  116. timeoutID: undefined
  117. };
  118. case SET_DEFAULT_TOOLBOX_BUTTONS: {
  119. const { primaryToolbarButtons, secondaryToolbarButtons } = action;
  120. return {
  121. ...state,
  122. primaryToolbarButtons,
  123. secondaryToolbarButtons
  124. };
  125. }
  126. case SET_SUBJECT:
  127. return {
  128. ...state,
  129. subject: action.subject
  130. };
  131. case SET_SUBJECT_SLIDE_IN:
  132. return {
  133. ...state,
  134. subjectSlideIn: action.subjectSlideIn
  135. };
  136. case SET_TOOLBAR_BUTTON:
  137. return _setButton(state, action);
  138. case SET_TOOLBAR_HOVERED:
  139. return {
  140. ...state,
  141. hovered: action.hovered
  142. };
  143. case SET_TOOLBOX_ALWAYS_VISIBLE:
  144. return {
  145. ...state,
  146. alwaysVisible: action.alwaysVisible
  147. };
  148. case SET_TOOLBOX_ENABLED:
  149. return {
  150. ...state,
  151. enabled: action.enabled
  152. };
  153. case SET_TOOLBOX_TIMEOUT:
  154. return {
  155. ...state,
  156. timeoutID: action.timeoutID,
  157. timeoutMS: action.timeoutMS
  158. };
  159. case SET_TOOLBOX_TIMEOUT_MS:
  160. return {
  161. ...state,
  162. timeoutMS: action.timeoutMS
  163. };
  164. case SET_TOOLBOX_VISIBLE:
  165. return {
  166. ...state,
  167. visible: action.visible
  168. };
  169. }
  170. return state;
  171. });
  172. /**
  173. * Sets new value of the button.
  174. *
  175. * @param {Object} state - Redux state.
  176. * @param {Object} action - Dispatched action.
  177. * @param {Object} action.button - Object describing toolbar button.
  178. * @param {Object} action.buttonName - The name of the button.
  179. * @private
  180. * @returns {Object}
  181. */
  182. function _setButton(state, { button, buttonName }): Object {
  183. const buttonDefinition = defaultToolbarButtons[buttonName];
  184. // We don't need to update if the button shouldn't be displayed
  185. if (!buttonDefinition || !buttonDefinition.isDisplayed()) {
  186. return {
  187. ...state
  188. };
  189. }
  190. const { primaryToolbarButtons, secondaryToolbarButtons } = state;
  191. let selectedButton = primaryToolbarButtons.get(buttonName);
  192. let place = 'primaryToolbarButtons';
  193. if (!selectedButton) {
  194. selectedButton = secondaryToolbarButtons.get(buttonName);
  195. place = 'secondaryToolbarButtons';
  196. }
  197. selectedButton = {
  198. ...selectedButton,
  199. ...button
  200. };
  201. const updatedToolbar = state[place].set(buttonName, selectedButton);
  202. return {
  203. ...state,
  204. [place]: new Map(updatedToolbar)
  205. };
  206. }