| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 | /* @flow */
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { FeedbackButton } from '../../feedback';
import UIEvents from '../../../../service/UI/UIEvents';
import {
    changeLocalRaiseHand,
    setProfileButtonUnclickable,
    showRecordingButton,
    toggleSideToolbarContainer
} from '../actions';
import Toolbar from './Toolbar';
import { getToolbarClassNames } from '../functions';
declare var APP: Object;
declare var config: Object;
/**
 * Implementation of secondary toolbar React component.
 *
 * @class SecondaryToolbar
 * @extends Component
 */
class SecondaryToolbar extends Component {
    state: Object;
    /**
     * Secondary toolbar property types.
     *
     * @static
     */
    static propTypes = {
        /**
         * Handler dispatching local "Raise hand".
         */
        _onLocalRaiseHandChanged: React.PropTypes.func,
        /**
         * Handler setting profile button unclickable.
         */
        _onSetProfileButtonUnclickable: React.PropTypes.func,
        /**
         * Handler for showing recording button.
         */
        _onShowRecordingButton: React.PropTypes.func,
        /**
         * Handler dispatching toggle toolbar container.
         */
        _onSideToolbarContainerToggled: React.PropTypes.func,
        /**
         * Contains map of secondary toolbar buttons.
         */
        _secondaryToolbarButtons: React.PropTypes.instanceOf(Map),
        /**
         * Shows whether toolbox is visible.
         */
        _visible: React.PropTypes.bool
    };
    /**
     * Constructs instance of SecondaryToolbar component.
     *
     * @param {Object} props - React component properties.
     */
    constructor(props) {
        super(props);
        const buttonHandlers = {
            /**
             * Mount handler for profile button.
             *
             * @type {Object}
             */
            profile: {
                onMount: () => {
                    APP.tokenData.isGuest
                    || this.props._onSetProfileButtonUnclickable(true);
                }
            },
            /**
             * Mount/Unmount handlers for raisehand button.
             *
             * @type {button}
             */
            raisehand: {
                onMount: () => {
                    APP.UI.addListener(UIEvents.LOCAL_RAISE_HAND_CHANGED,
                        this.props._onLocalRaiseHandChanged);
                },
                onUnmount: () => {
                    APP.UI.removeListener(UIEvents.LOCAL_RAISE_HAND_CHANGED,
                        this.props._onLocalRaiseHandChanged);
                }
            },
            /**
             * Mount handler for recording button.
             *
             * @type {Object}
             */
            recording: {
                onMount: () => {
                    if (config.enableRecording) {
                        this.props._onShowRecordingButton();
                    }
                }
            }
        };
        this.state = {
            /**
             * Object containing on mount/unmount handlers for toolbar buttons.
             *
             * @type {Object}
             */
            buttonHandlers
        };
    }
    /**
     * Register legacy UI listener.
     *
     * @returns {void}
     */
    componentDidMount(): void {
        APP.UI.addListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
            this.props._onSideToolbarContainerToggled);
    }
    /**
     * Unregisters legacy UI listener.
     *
     * @returns {void}
     */
    componentWillUnmount(): void {
        APP.UI.removeListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
            this.props._onSideToolbarContainerToggled);
    }
    /**
     * Renders secondary toolbar component.
     *
     * @returns {ReactElement}
     */
    render(): ReactElement<*> {
        const { buttonHandlers } = this.state;
        const { _secondaryToolbarButtons } = this.props;
        const { secondaryToolbarClassName } = getToolbarClassNames(this.props);
        return (
            <Toolbar
                buttonHandlers = { buttonHandlers }
                className = { secondaryToolbarClassName }
                toolbarButtons = { _secondaryToolbarButtons }>
                <FeedbackButton />
            </Toolbar>
        );
    }
}
/**
 * Maps some of Redux actions to component's props.
 *
 * @param {Function} dispatch - Redux action dispatcher.
 * @returns {{
 *      _onLocalRaiseHandChanged: Function,
 *      _onSetProfileButtonUnclickable: Function,
 *      _onShowRecordingButton: Function,
 *      _onSideToolbarContainerToggled
 * }}
 * @private
 */
function _mapDispatchToProps(dispatch: Function): Object {
    return {
        /**
         * Dispatches an action that 'hand' is raised.
         *
         * @param {boolean} isRaisedHand - Show whether hand is raised.
         * @returns {Object} Dispatched action.
         */
        _onLocalRaiseHandChanged(isRaisedHand: boolean) {
            return dispatch(changeLocalRaiseHand(isRaisedHand));
        },
        /**
         * Dispatches an action signalling to set profile button unclickable.
         *
         * @param {boolean} unclickable - Flag showing whether unclickable
         * property is true.
         * @returns {Object} Dispatched action.
         */
        _onSetProfileButtonUnclickable(unclickable: boolean) {
            return dispatch(setProfileButtonUnclickable(unclickable));
        },
        /**
         * Dispatches an action signalling that recording button should be
         * shown.
         *
         * @returns {Object} Dispatched action.
         */
        _onShowRecordingButton() {
            return dispatch(showRecordingButton());
        },
        /**
         * Dispatches an action signalling that side toolbar container is
         * toggled.
         *
         * @param {string} containerId - Id of side toolbar container.
         * @returns {Object} Dispatched action.
         */
        _onSideToolbarContainerToggled(containerId: string) {
            return dispatch(toggleSideToolbarContainer(containerId));
        }
    };
}
/**
 * Maps part of Redux state to component's props.
 *
 * @param {Object} state - Snapshot of Redux store.
 * @returns {{
 *      _secondaryToolbarButtons: Map,
 *      _visible: boolean
 * }}
 * @private
 */
function _mapStateToProps(state: Object): Object {
    const {
        secondaryToolbarButtons,
        visible
    } = state['features/toolbox'];
    return {
        /**
         * Default toolbar buttons for secondary toolbar.
         *
         * @protected
         * @type {Map}
         */
        _secondaryToolbarButtons: secondaryToolbarButtons,
        /**
         * Shows whether toolbar is visible.
         *
         * @protected
         * @type {boolean}
         */
        _visible: visible
    };
}
export default connect(_mapStateToProps, _mapDispatchToProps)(SecondaryToolbar);
 |