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.

TileViewButton.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import {
  4. createToolbarEvent,
  5. sendAnalytics
  6. } from '../../analytics';
  7. import { TILE_VIEW_ENABLED, getFeatureFlag } from '../../base/flags';
  8. import { translate } from '../../base/i18n';
  9. import { IconTileView } from '../../base/icons';
  10. import { getParticipantCount } from '../../base/participants';
  11. import { connect } from '../../base/redux';
  12. import { AbstractButton, type AbstractButtonProps } from '../../base/toolbox/components';
  13. import { setTileView } from '../actions';
  14. import { shouldDisplayTileView } from '../functions';
  15. import logger from '../logger';
  16. /**
  17. * The type of the React {@code Component} props of {@link TileViewButton}.
  18. */
  19. type Props = AbstractButtonProps & {
  20. /**
  21. * Whether or not tile view layout has been enabled as the user preference.
  22. */
  23. _tileViewEnabled: boolean,
  24. /**
  25. * Used to dispatch actions from the buttons.
  26. */
  27. dispatch: Dispatch<any>
  28. };
  29. /**
  30. * Component that renders a toolbar button for toggling the tile layout view.
  31. *
  32. * @extends AbstractButton
  33. */
  34. class TileViewButton<P: Props> extends AbstractButton<P, *> {
  35. accessibilityLabel = 'toolbar.accessibilityLabel.tileView';
  36. icon = IconTileView;
  37. label = 'toolbar.enterTileView';
  38. toggledLabel = 'toolbar.exitTileView';
  39. tooltip = 'toolbar.tileViewToggle';
  40. /**
  41. * Handles clicking / pressing the button.
  42. *
  43. * @override
  44. * @protected
  45. * @returns {void}
  46. */
  47. _handleClick() {
  48. const { _tileViewEnabled, dispatch } = this.props;
  49. sendAnalytics(createToolbarEvent(
  50. 'tileview.button',
  51. {
  52. 'is_enabled': _tileViewEnabled
  53. }));
  54. const value = !_tileViewEnabled;
  55. logger.debug(`Tile view ${value ? 'enable' : 'disable'}`);
  56. dispatch(setTileView(value));
  57. }
  58. /**
  59. * Indicates whether this button is in toggled state or not.
  60. *
  61. * @override
  62. * @protected
  63. * @returns {boolean}
  64. */
  65. _isToggled() {
  66. return this.props._tileViewEnabled;
  67. }
  68. }
  69. /**
  70. * Maps (parts of) the redux state to the associated props for the
  71. * {@code TileViewButton} component.
  72. *
  73. * @param {Object} state - The Redux state.
  74. * @param {Object} ownProps - The properties explicitly passed to the component instance.
  75. * @returns {Props}
  76. */
  77. function _mapStateToProps(state, ownProps) {
  78. const enabled = getFeatureFlag(state, TILE_VIEW_ENABLED, true);
  79. const lonelyMeeting = getParticipantCount(state) < 2;
  80. const { visible = enabled && !lonelyMeeting } = ownProps;
  81. return {
  82. _tileViewEnabled: shouldDisplayTileView(state),
  83. visible
  84. };
  85. }
  86. export default translate(connect(_mapStateToProps)(TileViewButton));