Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

FlipLocalVideoButton.tsx 2.7KB

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