jiti-meet/react/features/toolbox/components/SecondaryToolbar.web.js

189 lines
4.8 KiB
JavaScript
Raw Normal View History

2017-02-16 23:02:40 +00:00
/* @flow */
import PropTypes from 'prop-types';
2017-02-16 23:02:40 +00:00
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { FeedbackButton } from '../../feedback';
import UIEvents from '../../../../service/UI/UIEvents';
import {
toggleSideToolbarContainer
} from '../actions';
import { getToolbarClassNames } from '../functions';
2017-04-06 22:40:10 +00:00
import Toolbar from './Toolbar';
2017-02-16 23:02:40 +00:00
declare var APP: Object;
declare var config: Object;
2017-02-16 23:02:40 +00:00
/**
* Implementation of secondary toolbar React component.
*
* @class SecondaryToolbar
* @extends Component
*/
class SecondaryToolbar extends Component<*, *> {
2017-02-16 23:02:40 +00:00
state: Object;
/**
* Secondary toolbar property types.
*
* @static
*/
static propTypes = {
/**
* Application ID for callstats.io API. The {@code FeedbackButton} will
* display if defined.
*/
_callStatsID: PropTypes.string,
2017-04-21 10:00:50 +00:00
/**
* The indicator which determines whether the local participant is a
* guest in the conference.
*/
_isGuest: PropTypes.bool,
2017-04-21 10:00:50 +00:00
2017-02-16 23:02:40 +00:00
/**
* Handler dispatching toggle toolbar container.
*/
_onSideToolbarContainerToggled: PropTypes.func,
2017-02-16 23:02:40 +00:00
/**
* Contains map of secondary toolbar buttons.
*/
_secondaryToolbarButtons: PropTypes.instanceOf(Map),
2017-02-16 23:02:40 +00:00
/**
2017-04-01 05:52:40 +00:00
* Shows whether toolbox is visible.
2017-02-16 23:02:40 +00:00
*/
_visible: PropTypes.bool
2017-02-16 23:02:40 +00:00
};
/**
* Register legacy UI listener.
*
* @returns {void}
*/
componentDidMount(): void {
2017-04-06 22:40:10 +00:00
APP.UI.addListener(
UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
2017-02-16 23:02:40 +00:00
this.props._onSideToolbarContainerToggled);
}
/**
* Unregisters legacy UI listener.
*
* @returns {void}
*/
componentWillUnmount(): void {
2017-04-06 22:40:10 +00:00
APP.UI.removeListener(
UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
2017-02-16 23:02:40 +00:00
this.props._onSideToolbarContainerToggled);
}
/**
* Renders secondary toolbar component.
*
* @returns {ReactElement}
*/
render(): React$Element<*> | null {
const { _callStatsID, _secondaryToolbarButtons } = this.props;
// The number of buttons to show in the toolbar isn't fixed, it depends
2017-04-06 22:40:10 +00:00
// on the availability of features and configuration parameters. So
// there may be nothing to render.
if (_secondaryToolbarButtons.size === 0) {
return null;
}
2017-02-16 23:02:40 +00:00
const { secondaryToolbarClassName } = getToolbarClassNames(this.props);
return (
2017-04-01 05:52:40 +00:00
<Toolbar
2017-02-16 23:02:40 +00:00
className = { secondaryToolbarClassName }
2017-04-06 22:40:10 +00:00
toolbarButtons = { _secondaryToolbarButtons }
tooltipPosition = 'right'>
{ _callStatsID
? <FeedbackButton tooltipPosition = 'right' /> : null }
2017-04-01 05:52:40 +00:00
</Toolbar>
2017-02-16 23:02:40 +00:00
);
}
}
/**
* Maps some of Redux actions to component's props.
*
* @param {Function} dispatch - Redux action dispatcher.
* @returns {{
2017-04-06 22:40:10 +00:00
* _onSideToolbarContainerToggled
2017-02-16 23:02:40 +00:00
* }}
* @private
*/
function _mapDispatchToProps(dispatch: Function): Object {
return {
/**
* 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) {
dispatch(toggleSideToolbarContainer(containerId));
2017-02-16 23:02:40 +00:00
}
};
}
/**
* Maps part of Redux state to component's props.
*
* @param {Object} state - Snapshot of Redux store.
* @returns {{
2017-04-21 10:00:50 +00:00
* _isGuest: boolean,
2017-04-06 22:40:10 +00:00
* _secondaryToolbarButtons: Map,
* _visible: boolean
2017-02-16 23:02:40 +00:00
* }}
* @private
*/
function _mapStateToProps(state: Object): Object {
2017-10-05 22:54:13 +00:00
const { isGuest } = state['features/base/jwt'];
2017-04-21 10:00:50 +00:00
const { secondaryToolbarButtons, visible } = state['features/toolbox'];
const { callStatsID } = state['features/base/config'];
2017-02-16 23:02:40 +00:00
return {
/**
* Application ID for callstats.io API.
*/
_callStatsID: callStatsID,
2017-04-21 10:00:50 +00:00
/**
* The indicator which determines whether the local participant is a
* guest in the conference.
*
* @private
* @type {boolean}
*/
_isGuest: isGuest,
2017-02-16 23:02:40 +00:00
/**
* Default toolbar buttons for secondary toolbar.
*
2017-04-06 22:40:10 +00:00
* @private
2017-02-16 23:02:40 +00:00
* @type {Map}
*/
_secondaryToolbarButtons: secondaryToolbarButtons,
/**
2017-04-21 10:00:50 +00:00
* The indicator which determines whether the {@code SecondaryToolbar}
* is visible.
2017-02-16 23:02:40 +00:00
*
2017-04-06 22:40:10 +00:00
* @private
2017-02-16 23:02:40 +00:00
* @type {boolean}
*/
_visible: visible
};
}
export default connect(_mapStateToProps, _mapDispatchToProps)(SecondaryToolbar);