jiti-meet/react/features/shared-video/components/AbstractSharedVideoDialog.tsx

66 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-06-12 10:15:16 +00:00
import { Component } from 'react';
import { WithTranslation } from 'react-i18next';
2020-06-12 10:15:16 +00:00
import { IStore } from '../../app/types';
// eslint-disable-next-line lines-around-comment
// @ts-ignore
import { extractYoutubeIdOrURL } from '../functions';
2020-06-12 10:15:16 +00:00
/**
* The type of the React {@code Component} props of
* {@link AbstractSharedVideoDialog}.
2020-06-12 10:15:16 +00:00
*/
export interface IProps extends WithTranslation {
2020-06-12 10:15:16 +00:00
/**
* Invoked to update the shared video link.
2020-06-12 10:15:16 +00:00
*/
dispatch: IStore['dispatch'];
2020-06-12 10:15:16 +00:00
/**
* Function to be invoked after typing a valid video.
*/
onPostSubmit: Function;
}
2020-06-12 10:15:16 +00:00
/**
* Implements an abstract class for {@code SharedVideoDialog}.
2020-06-12 10:15:16 +00:00
*/
export default class AbstractSharedVideoDialog<S> extends Component < IProps, S > {
2021-05-13 11:36:19 +00:00
2020-06-12 10:15:16 +00:00
/**
* Instantiates a new component.
*
* @inheritdoc
*/
constructor(props: IProps) {
2020-06-12 10:15:16 +00:00
super(props);
this._onSetVideoLink = this._onSetVideoLink.bind(this);
}
/**
* Validates the entered video link by extracting the id and dispatches it.
*
* It returns a boolean to comply the Dialog behaviour:
* {@code true} - the dialog should be closed.
* {@code false} - the dialog should be left open.
*
* @param {string} link - The entered video link.
* @returns {boolean}
*/
_onSetVideoLink(link: string) {
const { onPostSubmit } = this.props;
const id = extractYoutubeIdOrURL(link);
if (!id) {
return false;
}
onPostSubmit(id);
return true;
}
2020-06-12 10:15:16 +00:00
}