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.

actions.web.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import {
  4. FULL_SCREEN_CHANGED,
  5. SET_FULL_SCREEN,
  6. SET_OVERFLOW_DRAWER
  7. } from './actionTypes';
  8. import {
  9. clearToolboxTimeout,
  10. setToolboxTimeout,
  11. setToolboxTimeoutMS,
  12. setToolboxVisible
  13. } from './actions.native';
  14. declare var interfaceConfig: Object;
  15. export * from './actions.native';
  16. /**
  17. * Docks/undocks the Toolbox.
  18. *
  19. * @param {boolean} dock - True if dock, false otherwise.
  20. * @returns {Function}
  21. */
  22. export function dockToolbox(dock: boolean): Function {
  23. return (dispatch: Dispatch<any>, getState: Function) => {
  24. const { timeoutMS, visible } = getState()['features/toolbox'];
  25. if (dock) {
  26. // First make sure the toolbox is shown.
  27. visible || dispatch(showToolbox());
  28. dispatch(clearToolboxTimeout());
  29. } else if (visible) {
  30. dispatch(
  31. setToolboxTimeout(
  32. () => dispatch(hideToolbox()),
  33. timeoutMS));
  34. } else {
  35. dispatch(showToolbox());
  36. }
  37. };
  38. }
  39. /**
  40. * Signals that full screen mode has been entered or exited.
  41. *
  42. * @param {boolean} fullScreen - Whether or not full screen mode is currently
  43. * enabled.
  44. * @returns {{
  45. * type: FULL_SCREEN_CHANGED,
  46. * fullScreen: boolean
  47. * }}
  48. */
  49. export function fullScreenChanged(fullScreen: boolean) {
  50. return {
  51. type: FULL_SCREEN_CHANGED,
  52. fullScreen
  53. };
  54. }
  55. /**
  56. * Hides the toolbox.
  57. *
  58. * @param {boolean} force - True to force the hiding of the toolbox without
  59. * caring about the extended toolbar side panels.
  60. * @returns {Function}
  61. */
  62. export function hideToolbox(force: boolean = false): Function {
  63. return (dispatch: Dispatch<any>, getState: Function) => {
  64. const state = getState();
  65. const {
  66. alwaysVisible,
  67. hovered,
  68. timeoutMS
  69. } = state['features/toolbox'];
  70. if (alwaysVisible) {
  71. return;
  72. }
  73. dispatch(clearToolboxTimeout());
  74. if (!force
  75. && (hovered
  76. || state['features/invite'].calleeInfoVisible
  77. || state['features/chat'].isOpen)) {
  78. dispatch(
  79. setToolboxTimeout(
  80. () => dispatch(hideToolbox()),
  81. timeoutMS));
  82. } else {
  83. dispatch(setToolboxVisible(false));
  84. }
  85. };
  86. }
  87. /**
  88. * Signals a request to enter or exit full screen mode.
  89. *
  90. * @param {boolean} fullScreen - True to enter full screen mode, false to exit.
  91. * @returns {{
  92. * type: SET_FULL_SCREEN,
  93. * fullScreen: boolean
  94. * }}
  95. */
  96. export function setFullScreen(fullScreen: boolean) {
  97. return {
  98. type: SET_FULL_SCREEN,
  99. fullScreen
  100. };
  101. }
  102. /**
  103. * Shows the toolbox for specified timeout.
  104. *
  105. * @param {number} timeout - Timeout for showing the toolbox.
  106. * @returns {Function}
  107. */
  108. export function showToolbox(timeout: number = 0): Object {
  109. return (dispatch: Dispatch<any>, getState: Function) => {
  110. const state = getState();
  111. const {
  112. alwaysVisible,
  113. enabled,
  114. timeoutMS,
  115. visible
  116. } = state['features/toolbox'];
  117. if (enabled && !visible) {
  118. dispatch(setToolboxVisible(true));
  119. // If the Toolbox is always visible, there's no need for a timeout
  120. // to toggle its visibility.
  121. if (!alwaysVisible) {
  122. dispatch(
  123. setToolboxTimeout(
  124. () => dispatch(hideToolbox()),
  125. timeout || timeoutMS));
  126. dispatch(setToolboxTimeoutMS(interfaceConfig.TOOLBAR_TIMEOUT));
  127. }
  128. }
  129. };
  130. }
  131. /**
  132. * Signals a request to display overflow as drawer.
  133. *
  134. * @param {boolean} displayAsDrawer - True to display overflow as drawer, false to preserve original behaviour.
  135. * @returns {{
  136. * type: SET_OVERFLOW_DRAWER,
  137. * displayAsDrawer: boolean
  138. * }}
  139. */
  140. export function setOverflowDrawer(displayAsDrawer: boolean) {
  141. return {
  142. type: SET_OVERFLOW_DRAWER,
  143. displayAsDrawer
  144. };
  145. }