feat(toolbox): create SettingsButton

Only on web, since there is currently no equivalent on mobile. It encapsulates
all funcionality related to opening the settings dialog / panel.
This commit is contained in:
Saúl Ibarra Corretgé 2018-04-18 12:12:42 +02:00 committed by Lyubo Marinov
parent 01cb4ac7c8
commit c7d72ee3f6
8 changed files with 109 additions and 43 deletions

View File

@ -18,7 +18,6 @@ import {
} from '../../base/participants';
import { getLocalVideoTrack, toggleScreensharing } from '../../base/tracks';
import { ChatCounter } from '../../chat';
import { openDeviceSelectionDialog } from '../../device-selection';
import { toggleDocument } from '../../etherpad';
import { openFeedbackDialog } from '../../feedback';
import {
@ -30,8 +29,7 @@ import {
import { openKeyboardShortcutsDialog } from '../../keyboard-shortcuts';
import { RECORDING_TYPES, toggleRecording } from '../../recording';
import { toggleSharedVideo } from '../../shared-video';
import { shouldShowOnlyDeviceSelection } from '../../settings';
import { toggleChat, toggleProfile, toggleSettings } from '../../side-panel';
import { toggleChat, toggleProfile } from '../../side-panel';
import { SpeakerStats } from '../../speaker-stats';
import {
OverflowMenuVideoQualityItem,
@ -44,7 +42,12 @@ import OverflowMenuButton from './OverflowMenuButton';
import OverflowMenuItem from './OverflowMenuItem';
import OverflowMenuProfileItem from './OverflowMenuProfileItem';
import ToolbarButton from './ToolbarButton';
import { AudioMuteButton, HangupButton, VideoMuteButton } from './buttons';
import {
AudioMuteButton,
HangupButton,
SettingsButton,
VideoMuteButton
} from './buttons';
type Props = {
@ -227,8 +230,6 @@ class Toolbox extends Component<Props, State> {
= this._onToolbarToggleRecording.bind(this);
this._onToolbarToggleScreenshare
= this._onToolbarToggleScreenshare.bind(this);
this._onToolbarToggleSettings
= this._onToolbarToggleSettings.bind(this);
this._onToolbarToggleSharedVideo
= this._onToolbarToggleSharedVideo.bind(this);
}
@ -509,21 +510,6 @@ class Toolbox extends Component<Props, State> {
}
}
/**
* Dispatches an action to toggle display of settings, be it the settings
* panel or directly to device selection.
*
* @private
* @returns {void}
*/
_doToggleSettings() {
if (shouldShowOnlyDeviceSelection()) {
this.props.dispatch(openDeviceSelectionDialog());
} else {
this.props.dispatch(toggleSettings());
}
}
/**
* Dispatches an action to toggle YouTube video sharing.
*
@ -862,21 +848,6 @@ class Toolbox extends Component<Props, State> {
this._doToggleScreenshare();
}
_onToolbarToggleSettings: () => void;
/**
* Creates an analytics toolbar event and dispatches an action for toggling
* settings display.
*
* @private
* @returns {void}
*/
_onToolbarToggleSettings() {
sendAnalytics(createToolbarEvent('settings'));
this._doToggleSettings();
}
_onToolbarToggleSharedVideo: () => void;
/**
@ -993,13 +964,10 @@ class Toolbox extends Component<Props, State> {
text = { _editingDocument
? t('toolbar.documentClose')
: t('toolbar.documentOpen') } />,
this._shouldShowButton('settings')
&& <OverflowMenuItem
accessibilityLabel = 'Settings'
icon = 'icon-settings'
key = 'settings'
onClick = { this._onToolbarToggleSettings }
text = { t('toolbar.Settings') } />,
<SettingsButton
key = 'settings'
showLabel = { true }
visible = { this._shouldShowButton('settings') } />,
this._shouldShowButton('stats')
&& <OverflowMenuItem
accessibilityLabel = 'Speaker stats'

View File

@ -0,0 +1 @@
export * from './native';

View File

@ -0,0 +1 @@
export * from './web';

View File

@ -1,3 +1,5 @@
export * from './_';
export { default as AudioMuteButton } from './AudioMuteButton';
export { default as HangupButton } from './HangupButton';
export { default as VideoMuteButton } from './VideoMuteButton';

View File

@ -0,0 +1,92 @@
// @flow
import { connect } from 'react-redux';
import { createToolbarEvent, sendAnalytics } from '../../../../analytics';
import { translate } from '../../../../base/i18n';
import { openDeviceSelectionDialog } from '../../../../device-selection';
import { toggleSettings } from '../../../../side-panel';
import AbstractButton from '../AbstractButton';
import type { Props as AbstractButtonProps } from '../AbstractButton';
declare var interfaceConfig: Object;
type Props = AbstractButtonProps & {
/**
* Whether we are in filmstrip only mode or not.
*/
_filmStripOnly: boolean,
/**
* Array containing the enabled settings sections.
*/
_sections: Array<string>,
/**
* The redux {@code dispatch} function.
*/
dispatch: Function
}
/**
* An abstract implementation of a button for accessing settings.
*/
class SettingsButton extends AbstractButton<Props, *> {
accessibilityLabel = 'Settings';
iconName = 'icon-settings';
label = 'toolbar.Settings';
tooltip = 'toolbar.Settings';
/**
* Handles clicking / pressing the button, and opens the appropriate dialog.
*
* @private
* @returns {void}
*/
_handleClick() {
const { _filmStripOnly, _sections, dispatch } = this.props;
sendAnalytics(createToolbarEvent('settings'));
if (_filmStripOnly
|| (_sections.length === 1 && _sections.includes('devices'))) {
dispatch(openDeviceSelectionDialog());
} else {
dispatch(toggleSettings());
}
}
/**
* Indicates whether this button is disabled or not.
*
* @override
* @private
* @returns {boolean}
*/
_isDisabled() {
return false;
}
}
/**
* Maps (parts of) the redux state to the associated props for the
* {@code SettingsButton} component.
*
* @param {Object} state - The Redux state.
* @private
* @returns {{
* _filmStripOnly: boolean
* }}
*/
function _mapStateToProps(state): Object { // eslint-disable-line no-unused-vars
// XXX: We are not currently using state here, but in the future, when
// interfaceConfig is part of redux we will.
return {
_filmStripOnly: Boolean(interfaceConfig.filmStripOnly),
_sections: interfaceConfig.SETTINGS_SECTIONS || []
};
}
export default translate(connect(_mapStateToProps)(SettingsButton));

View File

@ -0,0 +1 @@
export { default as SettingsButton } from './SettingsButton';

View File

@ -1,3 +1,4 @@
export { default as ToolbarButton } from './ToolbarButton';
export { default as ToolboxFilmstrip } from './ToolboxFilmstrip';
export { default as Toolbox } from './Toolbox';
export * from './buttons';