12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- // @flow
-
- import React from 'react';
-
- import { InputDialog } from '../../../base/dialog';
- import { connect } from '../../../base/redux';
- import { defaultMobileSharedVideoLink } from '../../constants';
- import { getYoutubeId } from '../../functions';
- import AbstractSharedVideoDialog from '../AbstractSharedVideoDialog';
-
- /**
- * Implements a component to render a display name prompt.
- */
- class SharedVideoDialog extends AbstractSharedVideoDialog<*> {
-
- /**
- * Implements React's {@link Component#render()}.
- *
- * @inheritdoc
- */
- render() {
- return (
- <InputDialog
- contentKey = 'dialog.shareVideoTitle'
- onSubmit = { this._onSetVideoLink }
- textInputProps = {{
- placeholder: defaultMobileSharedVideoLink
- }} />
- );
- }
-
- /**
- * 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;
- }
- }
-
- export default connect()(SharedVideoDialog);
|