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.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // @flow
  2. import React from 'react';
  3. import { InputDialog } from '../../../base/dialog';
  4. import { connect } from '../../../base/redux';
  5. import { defaultMobileSharedVideoLink } from '../../constants';
  6. import { getYoutubeId } from '../../functions';
  7. import AbstractSharedVideoDialog from '../AbstractSharedVideoDialog';
  8. /**
  9. * Implements a component to render a display name prompt.
  10. */
  11. class SharedVideoDialog extends AbstractSharedVideoDialog<*> {
  12. /**
  13. * Implements React's {@link Component#render()}.
  14. *
  15. * @inheritdoc
  16. */
  17. render() {
  18. return (
  19. <InputDialog
  20. contentKey = 'dialog.shareVideoTitle'
  21. onSubmit = { this._onSetVideoLink }
  22. textInputProps = {{
  23. placeholder: defaultMobileSharedVideoLink
  24. }} />
  25. );
  26. }
  27. /**
  28. * Validates the entered video link by extracting the id and dispatches it.
  29. *
  30. * It returns a boolean to comply the Dialog behaviour:
  31. * {@code true} - the dialog should be closed.
  32. * {@code false} - the dialog should be left open.
  33. *
  34. * @param {string} link - The entered video link.
  35. * @returns {boolean}
  36. */
  37. _onSetVideoLink(link: string) {
  38. if (!link || !link.trim()) {
  39. return false;
  40. }
  41. const videoId = getYoutubeId(link);
  42. if (videoId) {
  43. const { onPostSubmit } = this.props;
  44. onPostSubmit && onPostSubmit(link);
  45. return true;
  46. }
  47. return false;
  48. }
  49. }
  50. export default connect()(SharedVideoDialog);