code review

This commit is contained in:
Tudor-Ovidiu Avram
2021-05-13 14:36:19 +03:00
parent 4e4ff0f60f
commit 3ebfb1de70
10 changed files with 78 additions and 53 deletions

View File

@@ -4,13 +4,15 @@ import React from 'react';
import { InputDialog } from '../../../base/dialog';
import { connect } from '../../../base/redux';
import { defaultSharedVideoLink } from '../../constants';
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()}.
*
@@ -22,12 +24,38 @@ class SharedVideoDialog extends AbstractSharedVideoDialog<*> {
contentKey = 'dialog.shareVideoTitle'
onSubmit = { this._onSetVideoLink }
textInputProps = {{
placeholder: defaultSharedVideoLink
placeholder: defaultMobileSharedVideoLink
}} />
);
}
_onSetVideoLink: string => boolean;
/**
* 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);