選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AbstractSharedVideoDialog.tsx 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. * The allowed URL domains for shared video.
  12. */
  13. _allowedUrlDomains: Array<string>;
  14. /**
  15. * Invoked to update the shared video link.
  16. */
  17. dispatch: IStore['dispatch'];
  18. /**
  19. * Function to be invoked after typing a valid video.
  20. */
  21. onPostSubmit: Function;
  22. }
  23. /**
  24. * Implements an abstract class for {@code SharedVideoDialog}.
  25. */
  26. export default class AbstractSharedVideoDialog<S> extends Component < IProps, S > {
  27. /**
  28. * Instantiates a new component.
  29. *
  30. * @inheritdoc
  31. */
  32. constructor(props: IProps) {
  33. super(props);
  34. this._onSetVideoLink = this._onSetVideoLink.bind(this);
  35. }
  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. const { _allowedUrlDomains, onPostSubmit } = this.props;
  48. const id = extractYoutubeIdOrURL(link, _allowedUrlDomains);
  49. if (!id) {
  50. return false;
  51. }
  52. onPostSubmit(id);
  53. return true;
  54. }
  55. }