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.

SharedVideoDialog.tsx 2.7KB

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