From c2ca345dec7e88ea7a60b58953e58b1fbe912f02 Mon Sep 17 00:00:00 2001 From: Lyubo Marinov Date: Tue, 3 Oct 2017 17:26:13 -0500 Subject: [PATCH] [RN] Fix TypeError that getDefaultButtons is not a function --- .../toolbox/defaultToolbarButtons.native.js | 1 + .../toolbox/defaultToolbarButtons.web.js | 47 ++++++++++--------- react/features/toolbox/reducer.js | 22 ++++----- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/react/features/toolbox/defaultToolbarButtons.native.js b/react/features/toolbox/defaultToolbarButtons.native.js index e69de29bb..f237ddf58 100644 --- a/react/features/toolbox/defaultToolbarButtons.native.js +++ b/react/features/toolbox/defaultToolbarButtons.native.js @@ -0,0 +1 @@ +export default undefined; diff --git a/react/features/toolbox/defaultToolbarButtons.web.js b/react/features/toolbox/defaultToolbarButtons.web.js index 0a47d9d3e..01973a9c0 100644 --- a/react/features/toolbox/defaultToolbarButtons.web.js +++ b/react/features/toolbox/defaultToolbarButtons.web.js @@ -1,19 +1,12 @@ -/* @flow */ +// @flow import React from 'react'; -import _ from 'lodash'; import { ParticipantCounter } from '../contact-list'; import { openDeviceSelectionDialog } from '../device-selection'; - -import { - InfoDialogButton, - openInviteDialog -} from '../invite'; - -import { VideoQualityButton } from '../video-quality'; - +import { InfoDialogButton, openInviteDialog } from '../invite'; import UIEvents from '../../../service/UI/UIEvents'; +import { VideoQualityButton } from '../video-quality'; import ProfileButton from './components/ProfileButton'; @@ -21,19 +14,22 @@ declare var APP: Object; declare var interfaceConfig: Object; declare var JitsiMeetJS: Object; -let buttons: Object = {}; +/** + * The cache of {@link getDefaultButtons()}. + */ +let defaultButtons: Object; /** * Returns a map of all button descriptors and according properties. * - * @returns {*} - The maps of default button descriptors. + * @returns {Object} - The maps of default button descriptors. */ -function getDefaultButtons() { - if (!_.isEmpty(buttons)) { - return buttons; +export default function getDefaultButtons() { + if (defaultButtons) { + return defaultButtons; } - buttons = { + defaultButtons = { /** * The descriptor of the camera toolbar button. */ @@ -400,15 +396,24 @@ function getDefaultButtons() { } }; - Object.keys(buttons).forEach(name => { - const button = buttons[name]; + Object.keys(defaultButtons).forEach(name => { + const button = defaultButtons[name]; if (!button.isDisplayed) { - button.isDisplayed = () => !interfaceConfig.filmStripOnly; + button.isDisplayed = _isDisplayed; } }); - return buttons; + return defaultButtons; } -export default getDefaultButtons; +/** + * The default implementation of the {@code isDisplayed} method of the toolbar + * button definition returned by {@link getDefaultButtons()}. + * + * @returns {boolean} If the user intarface is full i.e. not filmstrip-only, + * then {@code true}; otherwise, {@code false}. + */ +function _isDisplayed() { + return !interfaceConfig.filmStripOnly; +} diff --git a/react/features/toolbox/reducer.js b/react/features/toolbox/reducer.js index 8e69f2c1a..51099494f 100644 --- a/react/features/toolbox/reducer.js +++ b/react/features/toolbox/reducer.js @@ -1,4 +1,4 @@ -/* @flow */ +// @flow import { ReducerRegistry } from '../base/redux'; @@ -155,7 +155,7 @@ ReducerRegistry.register( }; case SET_TOOLBAR_BUTTON: - return _setButton(state, action); + return _setToolbarButton(state, action); case SET_TOOLBAR_HOVERED: return { @@ -199,24 +199,24 @@ ReducerRegistry.register( }); /** - * Sets new value of the button. + * Reduces the redux action {@code SET_TOOLBAR_BUTTON} in the feature toolbox. * - * @param {Object} state - Redux state. - * @param {Object} action - Dispatched action. + * @param {Object} state - The redux state. + * @param {Object} action - The redux action of type {@code SET_TOOLBAR_BUTTON}. * @param {Object} action.button - Object describing toolbar button. * @param {Object} action.buttonName - The name of the button. * @private * @returns {Object} */ -function _setButton(state, { button, buttonName }): Object { - const buttons = getDefaultButtons(); - const buttonDefinition = buttons ? buttons[buttonName] : null; +function _setToolbarButton(state, { button, buttonName }): Object { + // XXX getDefaultButtons, defaultToolbarButtons, SET_TOOLBAR_BUTTON are + // abstractions fully implemented on Web only. + const buttons = getDefaultButtons && getDefaultButtons(); + const buttonDefinition = buttons && buttons[buttonName]; // We don't need to update if the button shouldn't be displayed if (!buttonDefinition || !buttonDefinition.isDisplayed()) { - return { - ...state - }; + return state; } const { primaryToolbarButtons, secondaryToolbarButtons } = state;