Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

HideSelfViewVideoButton.tsx 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import React, { PureComponent } from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { connect } from 'react-redux';
  4. import { IReduxState, IStore } from '../../../app/types';
  5. import { translate } from '../../../base/i18n/functions';
  6. import { updateSettings } from '../../../base/settings/actions';
  7. import { getHideSelfView } from '../../../base/settings/functions';
  8. import ContextMenuItem from '../../../base/ui/components/web/ContextMenuItem';
  9. /**
  10. * The type of the React {@code Component} props of {@link HideSelfViewVideoButton}.
  11. */
  12. interface IProps extends WithTranslation {
  13. /**
  14. * Button text class name.
  15. */
  16. className: string;
  17. /**
  18. * Whether or not to hide the self view.
  19. */
  20. disableSelfView: boolean;
  21. /**
  22. * The redux dispatch function.
  23. */
  24. dispatch: IStore['dispatch'];
  25. /**
  26. * Click handler executed aside from the main action.
  27. */
  28. onClick?: Function;
  29. }
  30. /**
  31. * Implements a React {@link Component} which displays a button for hiding the local video.
  32. *
  33. * @augments Component
  34. */
  35. class HideSelfViewVideoButton extends PureComponent<IProps> {
  36. /**
  37. * Initializes a new {@code HideSelfViewVideoButton} instance.
  38. *
  39. * @param {Object} props - The read-only React Component props with which
  40. * the new instance is to be initialized.
  41. */
  42. constructor(props: IProps) {
  43. super(props);
  44. // Bind event handlers so they are only bound once for every instance.
  45. this._onClick = this._onClick.bind(this);
  46. }
  47. /**
  48. * Implements React's {@link Component#render()}.
  49. *
  50. * @inheritdoc
  51. * @returns {null|ReactElement}
  52. */
  53. render() {
  54. const {
  55. className,
  56. t
  57. } = this.props;
  58. return (
  59. <ContextMenuItem
  60. accessibilityLabel = { t('videothumbnail.hideSelfView') }
  61. className = 'hideselflink'
  62. id = 'hideselfviewButton'
  63. onClick = { this._onClick }
  64. text = { t('videothumbnail.hideSelfView') }
  65. textClassName = { className } />
  66. );
  67. }
  68. /**
  69. * Hides the local video.
  70. *
  71. * @private
  72. * @returns {void}
  73. */
  74. _onClick() {
  75. const { disableSelfView, dispatch, onClick } = this.props;
  76. onClick?.();
  77. dispatch(updateSettings({
  78. disableSelfView: !disableSelfView
  79. }));
  80. }
  81. }
  82. /**
  83. * Maps (parts of) the Redux state to the associated {@code FlipLocalVideoButton}'s props.
  84. *
  85. * @param {Object} state - The Redux state.
  86. * @private
  87. * @returns {IProps}
  88. */
  89. function _mapStateToProps(state: IReduxState) {
  90. return {
  91. disableSelfView: Boolean(getHideSelfView(state))
  92. };
  93. }
  94. export default translate(connect(_mapStateToProps)(HideSelfViewVideoButton));