您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AbstractSharedVideoDialog.tsx 1.5KB

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