Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

actions.web.js 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { overwriteConfig } from '../base/config';
  4. import {
  5. CLEAR_TOOLBOX_TIMEOUT,
  6. FULL_SCREEN_CHANGED,
  7. SET_FULL_SCREEN,
  8. SET_OVERFLOW_DRAWER,
  9. SET_OVERFLOW_MENU_VISIBLE,
  10. SET_TOOLBAR_HOVERED,
  11. SET_TOOLBOX_TIMEOUT
  12. } from './actionTypes';
  13. import { setToolboxVisible } from './actions';
  14. import { getToolbarTimeout } from './functions';
  15. export * from './actions.any';
  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 state = getState();
  25. const { visible } = state['features/toolbox'];
  26. const toolbarTimeout = getToolbarTimeout(state);
  27. if (dock) {
  28. // First make sure the toolbox is shown.
  29. visible || dispatch(showToolbox());
  30. dispatch(clearToolboxTimeout());
  31. } else if (visible) {
  32. dispatch(
  33. setToolboxTimeout(
  34. () => dispatch(hideToolbox()),
  35. toolbarTimeout));
  36. } else {
  37. dispatch(showToolbox());
  38. }
  39. };
  40. }
  41. /**
  42. * Signals that full screen mode has been entered or exited.
  43. *
  44. * @param {boolean} fullScreen - Whether or not full screen mode is currently
  45. * enabled.
  46. * @returns {{
  47. * type: FULL_SCREEN_CHANGED,
  48. * fullScreen: boolean
  49. * }}
  50. */
  51. export function fullScreenChanged(fullScreen: boolean) {
  52. return {
  53. type: FULL_SCREEN_CHANGED,
  54. fullScreen
  55. };
  56. }
  57. /**
  58. * Hides the toolbox.
  59. *
  60. * @param {boolean} force - True to force the hiding of the toolbox without
  61. * caring about the extended toolbar side panels.
  62. * @returns {Function}
  63. */
  64. export function hideToolbox(force: boolean = false): Function {
  65. return (dispatch: Dispatch<any>, getState: Function) => {
  66. const state = getState();
  67. const { toolbarConfig: { alwaysVisible } } = state['features/base/config'];
  68. const { hovered } = state['features/toolbox'];
  69. const toolbarTimeout = getToolbarTimeout(state);
  70. if (alwaysVisible) {
  71. return;
  72. }
  73. dispatch(clearToolboxTimeout());
  74. const focusSelector = '.toolbox-content-items:focus-within,.filmstrip:focus-within,.remotevideomenu:hover';
  75. if (!force
  76. && (hovered
  77. || state['features/invite'].calleeInfoVisible
  78. || state['features/chat'].isOpen
  79. || document.querySelector(focusSelector))) {
  80. dispatch(
  81. setToolboxTimeout(
  82. () => dispatch(hideToolbox()),
  83. toolbarTimeout));
  84. } else {
  85. dispatch(setToolboxVisible(false));
  86. }
  87. };
  88. }
  89. /**
  90. * Signals a request to enter or exit full screen mode.
  91. *
  92. * @param {boolean} fullScreen - True to enter full screen mode, false to exit.
  93. * @returns {{
  94. * type: SET_FULL_SCREEN,
  95. * fullScreen: boolean
  96. * }}
  97. */
  98. export function setFullScreen(fullScreen: boolean) {
  99. return {
  100. type: SET_FULL_SCREEN,
  101. fullScreen
  102. };
  103. }
  104. /**
  105. * Shows the toolbox for specified timeout.
  106. *
  107. * @param {number} timeout - Timeout for showing the toolbox.
  108. * @returns {Function}
  109. */
  110. export function showToolbox(timeout: number = 0): Object {
  111. return (dispatch: Dispatch<any>, getState: Function) => {
  112. const state = getState();
  113. const {
  114. toolbarConfig: { initialTimeout, alwaysVisible },
  115. toolbarConfig
  116. } = state['features/base/config'];
  117. const toolbarTimeout = getToolbarTimeout(state);
  118. const {
  119. enabled,
  120. visible
  121. } = state['features/toolbox'];
  122. if (enabled && !visible) {
  123. dispatch(setToolboxVisible(true));
  124. // If the Toolbox is always visible, there's no need for a timeout
  125. // to toggle its visibility.
  126. if (!alwaysVisible) {
  127. if (typeof initialTimeout === 'number') {
  128. // reset `initialTimeout` once it is consumed once
  129. dispatch(overwriteConfig({ toolbarConfig: {
  130. ...toolbarConfig,
  131. initialTimeout: null
  132. } }));
  133. }
  134. dispatch(
  135. setToolboxTimeout(
  136. () => dispatch(hideToolbox()),
  137. timeout || initialTimeout || toolbarTimeout));
  138. }
  139. }
  140. };
  141. }
  142. /**
  143. * Signals a request to display overflow as drawer.
  144. *
  145. * @param {boolean} displayAsDrawer - True to display overflow as drawer, false to preserve original behaviour.
  146. * @returns {{
  147. * type: SET_OVERFLOW_DRAWER,
  148. * displayAsDrawer: boolean
  149. * }}
  150. */
  151. export function setOverflowDrawer(displayAsDrawer: boolean) {
  152. return {
  153. type: SET_OVERFLOW_DRAWER,
  154. displayAsDrawer
  155. };
  156. }
  157. /**
  158. * Signals that toolbox timeout should be cleared.
  159. *
  160. * @returns {{
  161. * type: CLEAR_TOOLBOX_TIMEOUT
  162. * }}
  163. */
  164. export function clearToolboxTimeout(): Object {
  165. return {
  166. type: CLEAR_TOOLBOX_TIMEOUT
  167. };
  168. }
  169. /**
  170. * Shows/hides the overflow menu.
  171. *
  172. * @param {boolean} visible - True to show it or false to hide it.
  173. * @returns {{
  174. * type: SET_OVERFLOW_MENU_VISIBLE,
  175. * visible: boolean
  176. * }}
  177. */
  178. export function setOverflowMenuVisible(visible: boolean): Object {
  179. return {
  180. type: SET_OVERFLOW_MENU_VISIBLE,
  181. visible
  182. };
  183. }
  184. /**
  185. * Signals that toolbar is hovered value should be changed.
  186. *
  187. * @param {boolean} hovered - Flag showing whether toolbar is hovered.
  188. * @returns {{
  189. * type: SET_TOOLBAR_HOVERED,
  190. * hovered: boolean
  191. * }}
  192. */
  193. export function setToolbarHovered(hovered: boolean): Object {
  194. return {
  195. type: SET_TOOLBAR_HOVERED,
  196. hovered
  197. };
  198. }
  199. /**
  200. * Dispatches an action which sets new timeout and clears the previous one.
  201. *
  202. * @param {Function} handler - Function to be invoked after the timeout.
  203. * @param {number} timeoutMS - Delay.
  204. * @returns {{
  205. * type: SET_TOOLBOX_TIMEOUT,
  206. * handler: Function,
  207. * timeoutMS: number
  208. * }}
  209. */
  210. export function setToolboxTimeout(handler: Function, timeoutMS: number): Object {
  211. return {
  212. type: SET_TOOLBOX_TIMEOUT,
  213. handler,
  214. timeoutMS
  215. };
  216. }