Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

reducer.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // @flow
  2. import { ReducerRegistry, set } from '../base/redux';
  3. import {
  4. CLEAR_TOOLBOX_TIMEOUT,
  5. FULL_SCREEN_CHANGED,
  6. SET_OVERFLOW_MENU_VISIBLE,
  7. SET_TOOLBAR_HOVERED,
  8. SET_TOOLBOX_ALWAYS_VISIBLE,
  9. SET_TOOLBOX_ENABLED,
  10. SET_TOOLBOX_TIMEOUT,
  11. SET_TOOLBOX_TIMEOUT_MS,
  12. SET_TOOLBOX_VISIBLE,
  13. TOGGLE_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. * enabled: boolean,
  23. * hovered: boolean,
  24. * overflowMenuVisible: boolean,
  25. * timeoutID: number,
  26. * timeoutMS: number,
  27. * visible: boolean
  28. * }}
  29. */
  30. function _getInitialState() {
  31. // Does the toolbar eventually fade out, or is it always visible?
  32. let alwaysVisible = false;
  33. // Toolbar (initial) visibility.
  34. let visible = false;
  35. // Default toolbox timeout for mobile app.
  36. let timeoutMS = 5000;
  37. if (typeof interfaceConfig !== 'undefined') {
  38. if (interfaceConfig.INITIAL_TOOLBAR_TIMEOUT) {
  39. timeoutMS = interfaceConfig.INITIAL_TOOLBAR_TIMEOUT;
  40. }
  41. if (typeof interfaceConfig.TOOLBAR_ALWAYS_VISIBLE !== 'undefined') {
  42. alwaysVisible = interfaceConfig.TOOLBAR_ALWAYS_VISIBLE;
  43. }
  44. }
  45. // When the toolbar is always visible, it must initially be visible too.
  46. if (alwaysVisible === true) {
  47. visible = true;
  48. }
  49. return {
  50. /**
  51. * The indicator which determines whether the Toolbox should always be
  52. * visible. When false, the toolbar will fade out after timeoutMS.
  53. *
  54. * @type {boolean}
  55. */
  56. alwaysVisible,
  57. /**
  58. * The indicator which determines whether the Toolbox is enabled.
  59. *
  60. * @type {boolean}
  61. */
  62. enabled: true,
  63. /**
  64. * The indicator which determines whether a Toolbar in the Toolbox is
  65. * hovered.
  66. *
  67. * @type {boolean}
  68. */
  69. hovered: false,
  70. /**
  71. * The indicator which determines whether the OverflowMenu is visible.
  72. *
  73. * @type {boolean}
  74. */
  75. overflowMenuVisible: false,
  76. /**
  77. * A number, non-zero value which identifies the timer created by a call
  78. * to setTimeout() with timeoutMS.
  79. *
  80. * @type {number|null}
  81. */
  82. timeoutID: null,
  83. /**
  84. * The delay in milliseconds before timeoutID executes (after its
  85. * initialization).
  86. *
  87. * @type {number}
  88. */
  89. timeoutMS,
  90. /**
  91. * The indicator which determines whether the Toolbox is visible.
  92. *
  93. * @type {boolean}
  94. */
  95. visible
  96. };
  97. }
  98. ReducerRegistry.register(
  99. 'features/toolbox',
  100. (state: Object = _getInitialState(), action: Object) => {
  101. switch (action.type) {
  102. case CLEAR_TOOLBOX_TIMEOUT:
  103. return {
  104. ...state,
  105. timeoutID: undefined
  106. };
  107. case FULL_SCREEN_CHANGED:
  108. return {
  109. ...state,
  110. fullScreen: action.fullScreen
  111. };
  112. case SET_OVERFLOW_MENU_VISIBLE:
  113. return {
  114. ...state,
  115. overflowMenuVisible: action.visible
  116. };
  117. case SET_TOOLBAR_HOVERED:
  118. return {
  119. ...state,
  120. hovered: action.hovered
  121. };
  122. case SET_TOOLBOX_ALWAYS_VISIBLE:
  123. return {
  124. ...state,
  125. alwaysVisible: action.alwaysVisible,
  126. visible: action.alwaysVisible === true ? true : state.visible
  127. };
  128. case SET_TOOLBOX_ENABLED:
  129. return {
  130. ...state,
  131. enabled: action.enabled
  132. };
  133. case SET_TOOLBOX_TIMEOUT:
  134. return {
  135. ...state,
  136. timeoutID: action.timeoutID,
  137. timeoutMS: action.timeoutMS
  138. };
  139. case SET_TOOLBOX_TIMEOUT_MS:
  140. return {
  141. ...state,
  142. timeoutMS: action.timeoutMS
  143. };
  144. case SET_TOOLBOX_VISIBLE:
  145. return set(state, 'visible', state.alwaysVisible || action.visible);
  146. case TOGGLE_TOOLBOX_VISIBLE:
  147. return set(state, 'visible', state.alwaysVisible || !state.visible);
  148. }
  149. return state;
  150. });