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

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