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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import {
  4. createToolbarEvent,
  5. sendAnalytics
  6. } from '../../analytics';
  7. import { translate } from '../../base/i18n';
  8. import { connect } from '../../base/redux';
  9. import {
  10. AbstractButton,
  11. type AbstractButtonProps
  12. } from '../../base/toolbox';
  13. import { setTileView } from '../actions';
  14. import logger from '../logger';
  15. /**
  16. * The type of the React {@code Component} props of {@link TileViewButton}.
  17. */
  18. type Props = AbstractButtonProps & {
  19. /**
  20. * Whether or not tile view layout has been enabled as the user preference.
  21. */
  22. _tileViewEnabled: boolean,
  23. /**
  24. * Used to dispatch actions from the buttons.
  25. */
  26. dispatch: Dispatch<any>
  27. };
  28. /**
  29. * Component that renders a toolbar button for toggling the tile layout view.
  30. *
  31. * @extends AbstractButton
  32. */
  33. class TileViewButton<P: Props> extends AbstractButton<P, *> {
  34. accessibilityLabel = 'toolbar.accessibilityLabel.tileView';
  35. iconName = 'icon-tiles-many';
  36. label = 'toolbar.enterTileView';
  37. toggledLabel = 'toolbar.exitTileView';
  38. toggledIconName = 'icon-tiles-many toggled';
  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. * @returns {{
  75. * _tileViewEnabled: boolean
  76. * }}
  77. */
  78. function _mapStateToProps(state) {
  79. return {
  80. _tileViewEnabled: state['features/video-layout'].tileViewEnabled
  81. };
  82. }
  83. export default translate(connect(_mapStateToProps)(TileViewButton));