Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

reducer.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* @flow */
  2. import { ReducerRegistry } from '../base/redux';
  3. import {
  4. CLEAR_TOOLBAR_TIMEOUT,
  5. SET_ALWAYS_VISIBLE_TOOLBAR,
  6. SET_SUBJECT,
  7. SET_SUBJECT_SLIDE_IN,
  8. SET_TOOLBAR_BUTTON,
  9. SET_TOOLBAR_HOVERED,
  10. SET_TOOLBAR_TIMEOUT,
  11. SET_TOOLBAR_TIMEOUT_NUMBER,
  12. SET_TOOLBAR_VISIBLE
  13. } from './actionTypes';
  14. import { getDefaultToolbarButtons } from './functions';
  15. declare var interfaceConfig: Object;
  16. /**
  17. * Returns initial state for toolbar's part of Redux store.
  18. *
  19. * @returns {{
  20. * primaryToolbarButtons: Map,
  21. * secondaryToolbarButtons: Map
  22. * }}
  23. * @private
  24. */
  25. function _getInitialState() {
  26. // Default toolbar timeout for mobile app.
  27. let toolbarTimeout = 5000;
  28. if (typeof interfaceConfig !== 'undefined'
  29. && interfaceConfig.INITIAL_TOOLBAR_TIMEOUT) {
  30. toolbarTimeout = interfaceConfig.INITIAL_TOOLBAR_TIMEOUT;
  31. }
  32. return {
  33. /**
  34. * Contains default toolbar buttons for primary and secondary toolbars.
  35. *
  36. * @type {Map}
  37. */
  38. ...getDefaultToolbarButtons(),
  39. /**
  40. * Shows whether toolbar is always visible.
  41. *
  42. * @type {boolean}
  43. */
  44. alwaysVisible: false,
  45. /**
  46. * Shows whether toolbar is hovered.
  47. *
  48. * @type {boolean}
  49. */
  50. hovered: false,
  51. /**
  52. * Contains text of conference subject.
  53. *
  54. * @type {string}
  55. */
  56. subject: '',
  57. /**
  58. * Shows whether subject is sliding in.
  59. *
  60. * @type {boolean}
  61. */
  62. subjectSlideIn: false,
  63. /**
  64. * Contains toolbar timeout id.
  65. *
  66. * @type {number|null}
  67. */
  68. timeoutId: null,
  69. /**
  70. * Contains delay of toolbar timeout.
  71. *
  72. * @type {number}
  73. */
  74. toolbarTimeout,
  75. /**
  76. * Shows whether toolbar is visible.
  77. *
  78. * @type {boolean}
  79. */
  80. visible: false
  81. };
  82. }
  83. ReducerRegistry.register(
  84. 'features/toolbar',
  85. (state: Object = _getInitialState(), action: Object) => {
  86. switch (action.type) {
  87. case CLEAR_TOOLBAR_TIMEOUT:
  88. return {
  89. ...state,
  90. timeoutId: undefined
  91. };
  92. case SET_ALWAYS_VISIBLE_TOOLBAR:
  93. return {
  94. ...state,
  95. alwaysVisible: action.alwaysVisible
  96. };
  97. case SET_SUBJECT:
  98. return {
  99. ...state,
  100. subject: action.subject
  101. };
  102. case SET_SUBJECT_SLIDE_IN:
  103. return {
  104. ...state,
  105. subjectSlideIn: action.subjectSlideIn
  106. };
  107. case SET_TOOLBAR_BUTTON:
  108. return _setButton(state, action);
  109. case SET_TOOLBAR_HOVERED:
  110. return {
  111. ...state,
  112. hovered: action.hovered
  113. };
  114. case SET_TOOLBAR_TIMEOUT:
  115. return {
  116. ...state,
  117. toolbarTimeout: action.toolbarTimeout,
  118. timeoutId: action.timeoutId
  119. };
  120. case SET_TOOLBAR_TIMEOUT_NUMBER:
  121. return {
  122. ...state,
  123. toolbarTimeout: action.toolbarTimeout
  124. };
  125. case SET_TOOLBAR_VISIBLE:
  126. return {
  127. ...state,
  128. visible: action.visible
  129. };
  130. }
  131. return state;
  132. });
  133. /**
  134. * Sets new value of the button.
  135. *
  136. * @param {Object} state - Redux state.
  137. * @param {Object} action - Dispatched action.
  138. * @param {Object} action.button - Object describing toolbar button.
  139. * @param {Object} action.buttonName - The name of the button.
  140. * @returns {Object}
  141. * @private
  142. */
  143. function _setButton(state, { buttonName, button }): Object {
  144. const {
  145. primaryToolbarButtons,
  146. secondaryToolbarButtons
  147. } = state;
  148. let selectedButton = primaryToolbarButtons.get(buttonName);
  149. let place = 'primaryToolbarButtons';
  150. if (!selectedButton) {
  151. selectedButton = secondaryToolbarButtons.get(buttonName);
  152. place = 'secondaryToolbarButtons';
  153. }
  154. selectedButton = {
  155. ...selectedButton,
  156. ...button
  157. };
  158. const updatedToolbar = state[place].set(buttonName, selectedButton);
  159. return {
  160. ...state,
  161. [place]: new Map(updatedToolbar)
  162. };
  163. }