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

HideSelfViewVideoButton.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* @flow */
  2. import React, { PureComponent } from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import { connect } from '../../../base/redux';
  5. import { updateSettings } from '../../../base/settings';
  6. import { NOTIFICATION_TIMEOUT_TYPE, showNotification } from '../../../notifications';
  7. import { openSettingsDialog, SETTINGS_TABS } from '../../../settings';
  8. import VideoMenuButton from './VideoMenuButton';
  9. /**
  10. * The type of the React {@code Component} props of {@link HideSelfViewVideoButton}.
  11. */
  12. type Props = {
  13. /**
  14. * Whether or not to hide the self view.
  15. */
  16. disableSelfView: boolean,
  17. /**
  18. * The redux dispatch function.
  19. */
  20. dispatch: Function,
  21. /**
  22. * Click handler executed aside from the main action.
  23. */
  24. onClick?: Function,
  25. /**
  26. * Invoked to obtain translated strings.
  27. */
  28. t: 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<Props> {
  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: Props) {
  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. t
  56. } = this.props;
  57. return (
  58. <VideoMenuButton
  59. buttonText = { t('videothumbnail.hideSelfView') }
  60. displayClass = 'hideselflink'
  61. id = 'hideselfviewbutton'
  62. onClick = { this._onClick } />
  63. );
  64. }
  65. _onClick: () => void;
  66. /**
  67. * Hides the local video.
  68. *
  69. * @private
  70. * @returns {void}
  71. */
  72. _onClick() {
  73. const { disableSelfView, dispatch, onClick } = this.props;
  74. onClick && onClick();
  75. dispatch(updateSettings({
  76. disableSelfView: !disableSelfView
  77. }));
  78. if (!disableSelfView) {
  79. dispatch(showNotification({
  80. titleKey: 'notify.selfViewTitle',
  81. customActionNameKey: [ 'settings.title' ],
  82. customActionHandler: [ () =>
  83. dispatch(openSettingsDialog(SETTINGS_TABS.PROFILE))
  84. ]
  85. }, NOTIFICATION_TIMEOUT_TYPE.STICKY));
  86. }
  87. }
  88. }
  89. /**
  90. * Maps (parts of) the Redux state to the associated {@code FlipLocalVideoButton}'s props.
  91. *
  92. * @param {Object} state - The Redux state.
  93. * @private
  94. * @returns {Props}
  95. */
  96. function _mapStateToProps(state) {
  97. const { disableSelfView } = state['features/base/config'];
  98. return {
  99. disableSelfView: Boolean(disableSelfView)
  100. };
  101. }
  102. export default translate(connect(_mapStateToProps)(HideSelfViewVideoButton));