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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // @flow
  2. import { Component } from 'react';
  3. import type { Dispatch } from 'redux';
  4. import { getYoutubeLink } 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 videoId = getYoutubeLink(link);
  52. if (videoId) {
  53. const { onPostSubmit } = this.props;
  54. onPostSubmit && onPostSubmit(videoId);
  55. return true;
  56. }
  57. return false;
  58. }
  59. }