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.

reducer.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* @flow */
  2. import { ReducerRegistry } from '../base/redux';
  3. import {
  4. CLEAR_TOOLBOX_TIMEOUT,
  5. SET_TOOLBOX_ALWAYS_VISIBLE,
  6. SET_SUBJECT,
  7. SET_SUBJECT_SLIDE_IN,
  8. SET_TOOLBAR_BUTTON,
  9. SET_TOOLBAR_HOVERED,
  10. SET_TOOLBOX_TIMEOUT,
  11. SET_TOOLBOX_TIMEOUT_MS,
  12. SET_TOOLBOX_VISIBLE
  13. } from './actionTypes';
  14. import { getDefaultToolbarButtons } from './functions';
  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. ...getDefaultToolbarButtons(),
  41. /**
  42. * The indicator which determines whether the Toolbox should always be
  43. * visible.
  44. *
  45. * @type {boolean}
  46. */
  47. alwaysVisible: false,
  48. /**
  49. * The indicator which determines whether a Toolbar in the Toolbox is
  50. * hovered.
  51. *
  52. * @type {boolean}
  53. */
  54. hovered: false,
  55. /**
  56. * The text of the conference subject.
  57. *
  58. * @type {string}
  59. */
  60. subject: '',
  61. /**
  62. * The indicator which determines whether the subject is sliding in.
  63. *
  64. * @type {boolean}
  65. */
  66. subjectSlideIn: false,
  67. /**
  68. * A number, non-zero value which identifies the timer created by a call
  69. * to setTimeout() with timeoutMS.
  70. *
  71. * @type {number|null}
  72. */
  73. timeoutID: null,
  74. /**
  75. * The delay in milliseconds before timeoutID executes (after its
  76. * initialization).
  77. *
  78. * @type {number}
  79. */
  80. timeoutMS,
  81. /**
  82. * The indicator which determines whether the Toolbox is visible.
  83. *
  84. * @type {boolean}
  85. */
  86. visible: false
  87. };
  88. }
  89. ReducerRegistry.register(
  90. 'features/toolbox',
  91. (state: Object = _getInitialState(), action: Object) => {
  92. switch (action.type) {
  93. case CLEAR_TOOLBOX_TIMEOUT:
  94. return {
  95. ...state,
  96. timeoutID: undefined
  97. };
  98. case SET_TOOLBOX_ALWAYS_VISIBLE:
  99. return {
  100. ...state,
  101. alwaysVisible: action.alwaysVisible
  102. };
  103. case SET_SUBJECT:
  104. return {
  105. ...state,
  106. subject: action.subject
  107. };
  108. case SET_SUBJECT_SLIDE_IN:
  109. return {
  110. ...state,
  111. subjectSlideIn: action.subjectSlideIn
  112. };
  113. case SET_TOOLBAR_BUTTON:
  114. return _setButton(state, action);
  115. case SET_TOOLBAR_HOVERED:
  116. return {
  117. ...state,
  118. hovered: action.hovered
  119. };
  120. case SET_TOOLBOX_TIMEOUT:
  121. return {
  122. ...state,
  123. timeoutID: action.timeoutID,
  124. timeoutMS: action.timeoutMS
  125. };
  126. case SET_TOOLBOX_TIMEOUT_MS:
  127. return {
  128. ...state,
  129. timeoutMS: action.timeoutMS
  130. };
  131. case SET_TOOLBOX_VISIBLE:
  132. return {
  133. ...state,
  134. visible: action.visible
  135. };
  136. }
  137. return state;
  138. });
  139. /**
  140. * Sets new value of the button.
  141. *
  142. * @param {Object} state - Redux state.
  143. * @param {Object} action - Dispatched action.
  144. * @param {Object} action.button - Object describing toolbar button.
  145. * @param {Object} action.buttonName - The name of the button.
  146. * @private
  147. * @returns {Object}
  148. */
  149. function _setButton(state, { buttonName, button }): Object {
  150. const {
  151. primaryToolbarButtons,
  152. secondaryToolbarButtons
  153. } = state;
  154. let selectedButton = primaryToolbarButtons.get(buttonName);
  155. let place = 'primaryToolbarButtons';
  156. if (!selectedButton) {
  157. selectedButton = secondaryToolbarButtons.get(buttonName);
  158. place = 'secondaryToolbarButtons';
  159. }
  160. selectedButton = {
  161. ...selectedButton,
  162. ...button
  163. };
  164. const updatedToolbar = state[place].set(buttonName, selectedButton);
  165. return {
  166. ...state,
  167. [place]: new Map(updatedToolbar)
  168. };
  169. }