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.4KB

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