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.

AbstractSharedVideoDialog.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // @flow
  2. import { Component } from 'react';
  3. import type { Dispatch } from 'redux';
  4. import { getYoutubeId } from '../functions';
  5. /**
  6. * The type of the React {@code Component} props of
  7. * {@link AbstractSharedVideoDialog}.
  8. */
  9. export type Props = {
  10. /**
  11. * Invoked to update the shared video link.
  12. */
  13. dispatch: Dispatch<any>,
  14. /**
  15. * Function to be invoked after typing a valid video.
  16. */
  17. onPostSubmit: Function,
  18. /**
  19. * Invoked to obtain translated strings.
  20. */
  21. t: Function
  22. };
  23. /**
  24. * Implements an abstract class for {@code SharedVideoDialog}.
  25. */
  26. export default class AbstractSharedVideoDialog<S: *> extends Component < Props, S > {
  27. /**
  28. * Instantiates a new component.
  29. *
  30. * @inheritdoc
  31. */
  32. constructor(props: Props) {
  33. super(props);
  34. this._onSetVideoLink = this._onSetVideoLink.bind(this);
  35. }
  36. _onSetVideoLink: string => boolean;
  37. /**
  38. * Validates the entered video link by extracting the id and dispatches it.
  39. *
  40. * It returns a boolean to comply the Dialog behaviour:
  41. * {@code true} - the dialog should be closed.
  42. * {@code false} - the dialog should be left open.
  43. *
  44. * @param {string} link - The entered video link.
  45. * @returns {boolean}
  46. */
  47. _onSetVideoLink(link: string) {
  48. if (!link || !link.trim()) {
  49. return false;
  50. }
  51. const youtubeId = getYoutubeId(link);
  52. const { onPostSubmit } = this.props;
  53. onPostSubmit(youtubeId || link);
  54. return true;
  55. }
  56. }