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.

FlipLocalVideoButton.js 2.7KB

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