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.7KB

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