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.tsx 1.5KB

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