2020-06-12 10:15:16 +00:00
|
|
|
import { Component } from 'react';
|
2022-08-05 12:07:28 +00:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2020-06-12 10:15:16 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
|
2022-08-05 12:07:28 +00:00
|
|
|
// @ts-ignore
|
2022-01-14 23:35:31 +00:00
|
|
|
import { extractYoutubeIdOrURL } from '../functions';
|
2021-08-02 12:55:52 +00:00
|
|
|
|
2020-06-12 10:15:16 +00:00
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of
|
2021-03-03 14:37:38 +00:00
|
|
|
* {@link AbstractSharedVideoDialog}.
|
2020-06-12 10:15:16 +00:00
|
|
|
*/
|
2022-08-05 12:07:28 +00:00
|
|
|
export interface Props extends WithTranslation {
|
2020-06-12 10:15:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-03-03 14:37:38 +00:00
|
|
|
* Invoked to update the shared video link.
|
2020-06-12 10:15:16 +00:00
|
|
|
*/
|
|
|
|
dispatch: Dispatch<any>,
|
|
|
|
|
|
|
|
/**
|
2021-03-03 14:37:38 +00:00
|
|
|
* Function to be invoked after typing a valid video.
|
|
|
|
*/
|
2022-08-05 12:07:28 +00:00
|
|
|
onPostSubmit: Function
|
|
|
|
}
|
2020-06-12 10:15:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-03-03 14:37:38 +00:00
|
|
|
* Implements an abstract class for {@code SharedVideoDialog}.
|
2020-06-12 10:15:16 +00:00
|
|
|
*/
|
2022-08-05 12:07:28 +00:00
|
|
|
export default class AbstractSharedVideoDialog<S> extends Component < Props, S > {
|
2021-05-13 11:36:19 +00:00
|
|
|
|
2020-06-12 10:15:16 +00:00
|
|
|
/**
|
|
|
|
* Instantiates a new component.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this._onSetVideoLink = this._onSetVideoLink.bind(this);
|
|
|
|
}
|
|
|
|
|
2021-08-02 12:55:52 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
2021-09-14 10:23:40 +00:00
|
|
|
|
2022-01-14 23:35:31 +00:00
|
|
|
const id = extractYoutubeIdOrURL(link);
|
2021-09-14 10:23:40 +00:00
|
|
|
|
2022-01-14 23:35:31 +00:00
|
|
|
if (!id) {
|
2021-09-14 10:23:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-08-02 12:55:52 +00:00
|
|
|
|
2022-01-14 23:35:31 +00:00
|
|
|
onPostSubmit(id);
|
2021-08-02 12:55:52 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-12 10:15:16 +00:00
|
|
|
}
|