2020-06-12 10:15:16 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { Component } from 'react';
|
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
|
2021-08-02 12:55:52 +00:00
|
|
|
import { getYoutubeId } from '../functions';
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
export type Props = {
|
|
|
|
|
|
|
|
/**
|
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.
|
|
|
|
*/
|
2021-04-16 09:43:34 +00:00
|
|
|
onPostSubmit: Function,
|
2021-03-03 14:37:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
2020-06-12 10:15:16 +00:00
|
|
|
*/
|
2021-03-03 14:37:38 +00:00
|
|
|
t: 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
|
|
|
*/
|
2021-03-03 14:37:38 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onSetVideoLink: string => boolean;
|
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) {
|
2021-08-18 09:09:04 +00:00
|
|
|
if (!link) {
|
2021-08-02 12:55:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-18 09:09:04 +00:00
|
|
|
const trimmedLink = link.trim();
|
|
|
|
|
|
|
|
if (!trimmedLink) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const youtubeId = getYoutubeId(trimmedLink);
|
2021-08-02 12:55:52 +00:00
|
|
|
const { onPostSubmit } = this.props;
|
|
|
|
|
2021-08-18 09:09:04 +00:00
|
|
|
onPostSubmit(youtubeId || trimmedLink);
|
2021-08-02 12:55:52 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-12 10:15:16 +00:00
|
|
|
}
|