Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

TileViewButton.js 2.5KB

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