2020-06-12 10:15:16 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import { InputDialog } from '../../../base/dialog';
|
|
|
|
import { connect } from '../../../base/redux';
|
2021-05-13 11:36:19 +00:00
|
|
|
import { defaultMobileSharedVideoLink } from '../../constants';
|
|
|
|
import { getYoutubeId } from '../../functions';
|
2021-03-03 14:37:38 +00:00
|
|
|
import AbstractSharedVideoDialog from '../AbstractSharedVideoDialog';
|
2020-06-12 10:15:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a component to render a display name prompt.
|
|
|
|
*/
|
2021-03-03 14:37:38 +00:00
|
|
|
class SharedVideoDialog extends AbstractSharedVideoDialog<*> {
|
2021-05-13 11:36:19 +00:00
|
|
|
|
2020-06-12 10:15:16 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<InputDialog
|
|
|
|
contentKey = 'dialog.shareVideoTitle'
|
|
|
|
onSubmit = { this._onSetVideoLink }
|
|
|
|
textInputProps = {{
|
2021-05-13 11:36:19 +00:00
|
|
|
placeholder: defaultMobileSharedVideoLink
|
2020-06-12 10:15:16 +00:00
|
|
|
}} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-13 11:36:19 +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) {
|
|
|
|
if (!link || !link.trim()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const videoId = getYoutubeId(link);
|
|
|
|
|
|
|
|
if (videoId) {
|
|
|
|
const { onPostSubmit } = this.props;
|
|
|
|
|
|
|
|
onPostSubmit && onPostSubmit(link);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2020-06-12 10:15:16 +00:00
|
|
|
}
|
|
|
|
|
2021-03-03 14:37:38 +00:00
|
|
|
export default connect()(SharedVideoDialog);
|