From 045a2d6acaf84526663028d40abf93fafa2c9cd3 Mon Sep 17 00:00:00 2001 From: Bettenbuk Zoltan Date: Wed, 30 Jan 2019 18:19:40 +0100 Subject: [PATCH] Extract isToolboxVisible function --- .../toolbox/components/native/Toolbox.js | 9 +++++---- react/features/toolbox/functions.any.js | 17 +++++++++++++++++ react/features/toolbox/functions.native.js | 3 +++ react/features/toolbox/functions.web.js | 2 ++ 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 react/features/toolbox/functions.any.js diff --git a/react/features/toolbox/components/native/Toolbox.js b/react/features/toolbox/components/native/Toolbox.js index 8fc0560ed..642f3383c 100644 --- a/react/features/toolbox/components/native/Toolbox.js +++ b/react/features/toolbox/components/native/Toolbox.js @@ -7,8 +7,12 @@ import { connect } from 'react-redux'; import { Container } from '../../../base/react'; import { ChatButton } from '../../../chat'; +import { isToolboxVisible } from '../../functions'; + import AudioMuteButton from '../AudioMuteButton'; import HangupButton from '../HangupButton'; +import VideoMuteButton from '../VideoMuteButton'; + import OverflowMenuButton from './OverflowMenuButton'; import styles, { chatButtonOverride, @@ -16,7 +20,6 @@ import styles, { toolbarButtonStyles, toolbarToggledButtonStyles } from './styles'; -import VideoMuteButton from '../VideoMuteButton'; /** * The number of buttons other than {@link HangupButton} to render in @@ -262,10 +265,8 @@ class Toolbox extends Component { * }} */ function _mapStateToProps(state: Object): Object { - const { alwaysVisible, enabled, visible } = state['features/toolbox']; - return { - _visible: enabled && (alwaysVisible || visible) + _visible: isToolboxVisible(state) }; } diff --git a/react/features/toolbox/functions.any.js b/react/features/toolbox/functions.any.js new file mode 100644 index 000000000..4b24a01cc --- /dev/null +++ b/react/features/toolbox/functions.any.js @@ -0,0 +1,17 @@ +// @flow + +import { toState } from '../base/redux'; + +/** + * Returns true if the toolbox is visible. + * + * @param {Object | Function} stateful - A function or object that can be + * resolved to Redux state by the function {@code toState}. + * @returns {boolean} + */ +export function isToolboxVisible(stateful: Object | Function) { + const { alwaysVisible, enabled, visible } + = toState(stateful)['features/toolbox']; + + return enabled && (alwaysVisible || visible); +} diff --git a/react/features/toolbox/functions.native.js b/react/features/toolbox/functions.native.js index e69de29bb..44e9d39cb 100644 --- a/react/features/toolbox/functions.native.js +++ b/react/features/toolbox/functions.native.js @@ -0,0 +1,3 @@ +// @flow + +export * from './functions.any'; diff --git a/react/features/toolbox/functions.web.js b/react/features/toolbox/functions.web.js index fe15a2baa..c196eb61b 100644 --- a/react/features/toolbox/functions.web.js +++ b/react/features/toolbox/functions.web.js @@ -1,5 +1,7 @@ // @flow +export * from './functions.any'; + declare var interfaceConfig: Object; /**