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

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