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

SharedVideoDialog.tsx 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { IReduxState } from '../../../app/types';
  4. import { hideDialog } from '../../../base/dialog/actions';
  5. import { translate } from '../../../base/i18n/functions';
  6. import Dialog from '../../../base/ui/components/web/Dialog';
  7. import Input from '../../../base/ui/components/web/Input';
  8. import AbstractSharedVideoDialog from '../AbstractSharedVideoDialog';
  9. /**
  10. * Component that renders the video share dialog.
  11. *
  12. * @returns {React$Element<any>}
  13. */
  14. class SharedVideoDialog extends AbstractSharedVideoDialog<any> {
  15. /**
  16. * Instantiates a new component.
  17. *
  18. * @inheritdoc
  19. */
  20. constructor(props: any) {
  21. super(props);
  22. this.state = {
  23. value: '',
  24. okDisabled: true,
  25. error: false
  26. };
  27. this._onChange = this._onChange.bind(this);
  28. this._onSubmitValue = this._onSubmitValue.bind(this);
  29. }
  30. /**
  31. * Callback for the onChange event of the field.
  32. *
  33. * @param {string} value - The static event.
  34. * @returns {void}
  35. */
  36. _onChange(value: string) {
  37. this.setState({
  38. value,
  39. okDisabled: !value
  40. });
  41. }
  42. /**
  43. * Callback to be invoked when the value of the link input is submitted.
  44. *
  45. * @returns {boolean}
  46. */
  47. _onSubmitValue() {
  48. const result = super._onSetVideoLink(this.state.value);
  49. if (result) {
  50. this.props.dispatch(hideDialog());
  51. } else {
  52. this.setState({
  53. error: true
  54. });
  55. }
  56. return result;
  57. }
  58. /**
  59. * Implements React's {@link Component#render()}.
  60. *
  61. * @inheritdoc
  62. */
  63. render() {
  64. const { t } = this.props;
  65. const { error } = this.state;
  66. return (
  67. <Dialog
  68. disableAutoHideOnSubmit = { true }
  69. ok = {{
  70. disabled: this.state.okDisabled,
  71. translationKey: 'dialog.Share'
  72. }}
  73. onSubmit = { this._onSubmitValue }
  74. titleKey = 'dialog.shareVideoTitle'>
  75. <Input
  76. autoFocus = { true }
  77. bottomLabel = { error && t('dialog.sharedVideoDialogError') }
  78. className = 'dialog-bottom-margin'
  79. error = { error }
  80. id = 'shared-video-url-input'
  81. label = { t('dialog.videoLink') }
  82. name = 'sharedVideoUrl'
  83. onChange = { this._onChange }
  84. placeholder = { t('dialog.sharedVideoLinkPlaceholder') }
  85. type = 'text'
  86. value = { this.state.value } />
  87. </Dialog>
  88. );
  89. }
  90. }
  91. /**
  92. * Maps part of the Redux state to the props of this component.
  93. *
  94. * @param {Object} state - The Redux state.
  95. * @private
  96. * @returns {IProps}
  97. */
  98. function mapStateToProps(state: IReduxState) {
  99. const { allowedUrlDomains } = state['features/shared-video'];
  100. return {
  101. _allowedUrlDomains: allowedUrlDomains
  102. };
  103. }
  104. export default translate(connect(mapStateToProps)(SharedVideoDialog));