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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. } from './actionTypes';
  14. declare var interfaceConfig: Object;
  15. /**
  16. * Returns initial state for toolbox's part of Redux store.
  17. *
  18. * @private
  19. * @returns {{
  20. * alwaysVisible: boolean,
  21. * enabled: boolean,
  22. * hovered: boolean,
  23. * overflowMenuVisible: boolean,
  24. * timeoutID: number,
  25. * timeoutMS: number,
  26. * visible: boolean
  27. * }}
  28. */
  29. function _getInitialState() {
  30. // Default toolbox timeout for mobile app.
  31. let timeoutMS = 5000;
  32. if (typeof interfaceConfig !== 'undefined'
  33. && interfaceConfig.INITIAL_TOOLBAR_TIMEOUT) {
  34. timeoutMS = interfaceConfig.INITIAL_TOOLBAR_TIMEOUT;
  35. }
  36. return {
  37. /**
  38. * The indicator which determines whether the Toolbox should always be
  39. * visible.
  40. *
  41. * @type {boolean}
  42. */
  43. alwaysVisible: false,
  44. /**
  45. * The indicator which determines whether the Toolbox is enabled.
  46. *
  47. * @type {boolean}
  48. */
  49. enabled: true,
  50. /**
  51. * The indicator which determines whether a Toolbar in the Toolbox is
  52. * hovered.
  53. *
  54. * @type {boolean}
  55. */
  56. hovered: false,
  57. /**
  58. * The indicator which determines whether the OverflowMenu is visible.
  59. *
  60. * @type {boolean}
  61. */
  62. overflowMenuVisible: false,
  63. /**
  64. * A number, non-zero value which identifies the timer created by a call
  65. * to setTimeout() with timeoutMS.
  66. *
  67. * @type {number|null}
  68. */
  69. timeoutID: null,
  70. /**
  71. * The delay in milliseconds before timeoutID executes (after its
  72. * initialization).
  73. *
  74. * @type {number}
  75. */
  76. timeoutMS,
  77. /**
  78. * The indicator which determines whether the Toolbox is visible.
  79. *
  80. * @type {boolean}
  81. */
  82. visible: false
  83. };
  84. }
  85. ReducerRegistry.register(
  86. 'features/toolbox',
  87. (state: Object = _getInitialState(), action: Object) => {
  88. switch (action.type) {
  89. case CLEAR_TOOLBOX_TIMEOUT:
  90. return {
  91. ...state,
  92. timeoutID: undefined
  93. };
  94. case FULL_SCREEN_CHANGED:
  95. return {
  96. ...state,
  97. fullScreen: action.fullScreen
  98. };
  99. case SET_OVERFLOW_MENU_VISIBLE:
  100. return {
  101. ...state,
  102. overflowMenuVisible: action.visible
  103. };
  104. case SET_TOOLBAR_HOVERED:
  105. return {
  106. ...state,
  107. hovered: action.hovered
  108. };
  109. case SET_TOOLBOX_ALWAYS_VISIBLE:
  110. return {
  111. ...state,
  112. alwaysVisible: action.alwaysVisible
  113. };
  114. case SET_TOOLBOX_ENABLED:
  115. return {
  116. ...state,
  117. enabled: action.enabled
  118. };
  119. case SET_TOOLBOX_TIMEOUT:
  120. return {
  121. ...state,
  122. timeoutID: action.timeoutID,
  123. timeoutMS: action.timeoutMS
  124. };
  125. case SET_TOOLBOX_TIMEOUT_MS:
  126. return {
  127. ...state,
  128. timeoutMS: action.timeoutMS
  129. };
  130. case SET_TOOLBOX_VISIBLE:
  131. return set(state, 'visible', action.visible);
  132. }
  133. return state;
  134. });