import React, {Component} from "react"; import { withModalMounter } from '/imports/ui/components/modal/service'; import ModalBase from '/imports/ui/components/modal/base/component'; import Button from '/imports/ui/components/button/component'; import {styles} from './styles'; import { defineMessages, injectIntl } from 'react-intl'; const intlMessages = defineMessages({ start: { id: 'app.externalVideo.start', description: 'Share youtube video', }, stop: { id: 'app.externalVideo.stop', description: 'Stop sharing video', }, urlError: { id: 'app.externalVideo.urlError', description: 'Not a video URL error', }, input: { id: 'app.externalVideo.input', description: 'Video URL', }, title: { id: 'app.externalVideo.title', description: 'Modal title', }, close: { id: 'app.externalVideo.close', description: 'Close', }, }); const YOUTUBE_PREFIX = "https://youtube.com/watch?v="; const getUrlFromVideoId = (id) => { return id ? `${YOUTUBE_PREFIX}${id}` : ''; } class ExternalVideoModal extends Component { const { videoId } = this.props; state = { url: getUrlFromVideoId(videoId), sharing: videoId, }; isUrlEmpty = () => { const url = this.state.url; return !url || url.length == 0; } isUrlValid = () => { const url = this.state.url; const regexp = RegExp('^(https?\:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+$'); return !this.isUrlEmpty() && url.match(regexp); } startWatchingHandler = () => { this.props.startWatching(this.state.url); this.props.closeModal(); } stopWatchingHandler = () => { this.props.stopWatching(); this.props.closeModal(); } updateVideoUrlHandler = (ev) => { console.log(this.props); this.setState({...this.state, url: ev.target.value}); } renderUrlError = () => { const { intl } = this.props; const { url } = this.state; const valid = !this.isUrlEmpty() && url.length > 3 && !this.isUrlValid(); return ( valid ? (
{intl.formatMessage(intlMessages.urlError)}
) : null ); } render() { const { intl } = this.props.intl; return (

{intl.formatMessage(intlMessages.title)}

{this.renderUrlError()}
); } } export default injectIntl(withModalMounter(ExternalVideoModal));