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

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