You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SettingsButton.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // @flow
  2. import { createToolbarEvent, sendAnalytics } from '../../../analytics';
  3. import { translate } from '../../../base/i18n';
  4. import { IconSettings } from '../../../base/icons';
  5. import { connect } from '../../../base/redux';
  6. import { AbstractButton } from '../../../base/toolbox';
  7. import type { AbstractButtonProps } from '../../../base/toolbox';
  8. import { openDeviceSelectionPopup } from '../../../device-selection';
  9. import { openSettingsDialog } from '../../actions';
  10. import { SETTINGS_TABS } from '../../constants';
  11. declare var interfaceConfig: Object;
  12. /**
  13. * The type of the React {@code Component} props of {@link SettingsButton}.
  14. */
  15. type Props = AbstractButtonProps & {
  16. /**
  17. * Whether we are in filmstrip only mode or not.
  18. */
  19. _filmstripOnly: boolean,
  20. /**
  21. * The default tab at which the settings dialog will be opened.
  22. */
  23. defaultTab: string,
  24. /**
  25. * The redux {@code dispatch} function.
  26. */
  27. dispatch: Function
  28. };
  29. /**
  30. * An abstract implementation of a button for accessing settings.
  31. */
  32. class SettingsButton extends AbstractButton<Props, *> {
  33. accessibilityLabel = 'toolbar.accessibilityLabel.Settings';
  34. icon = IconSettings;
  35. label = 'toolbar.Settings';
  36. tooltip = 'toolbar.Settings';
  37. /**
  38. * Handles clicking / pressing the button, and opens the appropriate dialog.
  39. *
  40. * @protected
  41. * @returns {void}
  42. */
  43. _handleClick() {
  44. const {
  45. _filmstripOnly,
  46. defaultTab = SETTINGS_TABS.DEVICES,
  47. dispatch } = this.props;
  48. sendAnalytics(createToolbarEvent('settings'));
  49. if (_filmstripOnly) {
  50. dispatch(openDeviceSelectionPopup());
  51. } else {
  52. dispatch(openSettingsDialog(defaultTab));
  53. }
  54. }
  55. }
  56. /**
  57. * Maps (parts of) the redux state to the associated props for the
  58. * {@code SettingsButton} component.
  59. *
  60. * @param {Object} state - The Redux state.
  61. * @private
  62. * @returns {{
  63. * _filmstripOnly: boolean
  64. * }}
  65. */
  66. function _mapStateToProps(state): Object { // eslint-disable-line no-unused-vars
  67. // XXX: We are not currently using state here, but in the future, when
  68. // interfaceConfig is part of redux we will.
  69. return {
  70. _filmstripOnly: Boolean(interfaceConfig.filmStripOnly)
  71. };
  72. }
  73. export default translate(connect(_mapStateToProps)(SettingsButton));