2019-01-16 04:44:41 +08:00
|
|
|
import React, { Component } from 'react';
|
2018-11-30 01:24:02 +08:00
|
|
|
import { withModalMounter } from '/imports/ui/components/modal/service';
|
2019-05-09 03:13:05 +08:00
|
|
|
import Modal from '/imports/ui/components/modal/simple/component';
|
2018-11-30 01:24:02 +08:00
|
|
|
import Button from '/imports/ui/components/button/component';
|
|
|
|
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2019-07-17 04:33:27 +08:00
|
|
|
import { isUrlValid } from '../service';
|
2019-01-16 04:44:41 +08:00
|
|
|
|
|
|
|
import { styles } from './styles';
|
2018-11-30 01:24:02 +08:00
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
start: {
|
|
|
|
id: 'app.externalVideo.start',
|
2019-08-27 04:39:20 +08:00
|
|
|
description: 'Share external video',
|
2018-11-30 01:24:02 +08:00
|
|
|
},
|
|
|
|
urlError: {
|
|
|
|
id: 'app.externalVideo.urlError',
|
|
|
|
description: 'Not a video URL error',
|
|
|
|
},
|
|
|
|
input: {
|
|
|
|
id: 'app.externalVideo.input',
|
|
|
|
description: 'Video URL',
|
|
|
|
},
|
2019-03-12 00:14:34 +08:00
|
|
|
urlInput: {
|
|
|
|
id: 'app.externalVideo.urlInput',
|
|
|
|
description: 'URL input field placeholder',
|
|
|
|
},
|
2018-11-30 01:24:02 +08:00
|
|
|
title: {
|
|
|
|
id: 'app.externalVideo.title',
|
|
|
|
description: 'Modal title',
|
|
|
|
},
|
|
|
|
close: {
|
|
|
|
id: 'app.externalVideo.close',
|
|
|
|
description: 'Close',
|
|
|
|
},
|
2019-03-15 21:04:19 +08:00
|
|
|
note: {
|
|
|
|
id: 'app.externalVideo.noteLabel',
|
2019-08-27 04:39:20 +08:00
|
|
|
description: 'provides hint about Shared External videos',
|
2019-03-15 21:04:19 +08:00
|
|
|
},
|
2018-11-30 01:24:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
class ExternalVideoModal extends Component {
|
2019-01-16 04:44:41 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2019-07-13 04:08:55 +08:00
|
|
|
const { videoUrl } = props;
|
2019-01-15 03:10:08 +08:00
|
|
|
|
2019-01-16 04:44:41 +08:00
|
|
|
this.state = {
|
2019-07-13 04:08:55 +08:00
|
|
|
url: videoUrl,
|
|
|
|
sharing: videoUrl,
|
2019-01-16 04:44:41 +08:00
|
|
|
};
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2019-01-16 04:44:41 +08:00
|
|
|
this.startWatchingHandler = this.startWatchingHandler.bind(this);
|
|
|
|
this.updateVideoUrlHandler = this.updateVideoUrlHandler.bind(this);
|
|
|
|
this.renderUrlError = this.renderUrlError.bind(this);
|
|
|
|
this.updateVideoUrlHandler = this.updateVideoUrlHandler.bind(this);
|
2018-11-30 01:24:02 +08:00
|
|
|
}
|
|
|
|
|
2019-01-16 04:44:41 +08:00
|
|
|
startWatchingHandler() {
|
2019-06-17 22:10:45 +08:00
|
|
|
const {
|
|
|
|
startWatching,
|
|
|
|
closeModal,
|
|
|
|
} = this.props;
|
|
|
|
|
2019-01-18 01:12:32 +08:00
|
|
|
const { url } = this.state;
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2019-05-02 04:09:49 +08:00
|
|
|
startWatching(url.trim());
|
2019-01-16 04:44:41 +08:00
|
|
|
closeModal();
|
2018-11-30 01:24:02 +08:00
|
|
|
}
|
|
|
|
|
2019-01-16 04:44:41 +08:00
|
|
|
updateVideoUrlHandler(ev) {
|
2019-01-18 01:12:32 +08:00
|
|
|
this.setState({ url: ev.target.value });
|
2018-11-30 01:24:02 +08:00
|
|
|
}
|
|
|
|
|
2019-01-16 04:44:41 +08:00
|
|
|
renderUrlError() {
|
2019-01-15 03:10:08 +08:00
|
|
|
const { intl } = this.props;
|
|
|
|
const { url } = this.state;
|
|
|
|
|
2019-01-16 04:44:41 +08:00
|
|
|
const valid = (!url || url.length <= 3) || isUrlValid(url);
|
2018-11-30 01:24:02 +08:00
|
|
|
|
|
|
|
return (
|
2019-01-16 04:44:41 +08:00
|
|
|
!valid
|
|
|
|
? (
|
|
|
|
<div className={styles.urlError}>
|
|
|
|
{intl.formatMessage(intlMessages.urlError)}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
: null
|
2018-11-30 01:24:02 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-09-11 02:04:42 +08:00
|
|
|
const { intl, closeModal } = this.props;
|
2019-01-16 04:44:41 +08:00
|
|
|
const { url, sharing } = this.state;
|
|
|
|
|
2019-07-16 04:12:07 +08:00
|
|
|
const startDisabled = !isUrlValid(url);
|
2018-11-30 01:24:02 +08:00
|
|
|
|
|
|
|
return (
|
2019-05-09 03:13:05 +08:00
|
|
|
<Modal
|
2018-11-30 01:24:02 +08:00
|
|
|
overlayClassName={styles.overlay}
|
|
|
|
className={styles.modal}
|
2019-01-16 04:44:41 +08:00
|
|
|
onRequestClose={closeModal}
|
2019-05-09 03:13:05 +08:00
|
|
|
contentLabel={intl.formatMessage(intlMessages.title)}
|
|
|
|
hideBorder
|
2018-11-30 01:24:02 +08:00
|
|
|
>
|
2021-10-29 02:37:56 +08:00
|
|
|
<header data-test="videoModalHeader" className={styles.header}>
|
2019-01-16 04:44:41 +08:00
|
|
|
<h3 className={styles.title}>{intl.formatMessage(intlMessages.title)}</h3>
|
2018-11-30 01:24:02 +08:00
|
|
|
</header>
|
|
|
|
|
|
|
|
<div className={styles.content}>
|
|
|
|
<div className={styles.videoUrl}>
|
2021-01-07 00:53:22 +08:00
|
|
|
<label htmlFor="video-modal-input">
|
2018-11-30 01:24:02 +08:00
|
|
|
{intl.formatMessage(intlMessages.input)}
|
2019-01-16 04:44:41 +08:00
|
|
|
<input
|
|
|
|
id="video-modal-input"
|
|
|
|
onChange={this.updateVideoUrlHandler}
|
|
|
|
name="video-modal-input"
|
2019-03-12 00:14:34 +08:00
|
|
|
placeholder={intl.formatMessage(intlMessages.urlInput)}
|
2019-04-24 03:59:10 +08:00
|
|
|
disabled={sharing}
|
2019-08-27 04:39:20 +08:00
|
|
|
aria-describedby="exernal-video-note"
|
2019-01-16 04:44:41 +08:00
|
|
|
/>
|
2018-11-30 01:24:02 +08:00
|
|
|
</label>
|
2019-08-27 04:39:20 +08:00
|
|
|
<div className={styles.externalVideoNote} id="external-video-note">
|
2019-03-15 21:04:19 +08:00
|
|
|
{intl.formatMessage(intlMessages.note)}
|
|
|
|
</div>
|
2018-11-30 01:24:02 +08:00
|
|
|
</div>
|
|
|
|
|
2019-04-24 03:59:10 +08:00
|
|
|
<div>
|
2019-01-16 04:44:41 +08:00
|
|
|
{this.renderUrlError()}
|
|
|
|
</div>
|
2018-11-30 01:24:02 +08:00
|
|
|
|
|
|
|
<Button
|
2019-04-25 01:19:35 +08:00
|
|
|
className={styles.startBtn}
|
|
|
|
label={intl.formatMessage(intlMessages.start)}
|
|
|
|
onClick={this.startWatchingHandler}
|
|
|
|
disabled={startDisabled}
|
2019-01-16 04:44:41 +08:00
|
|
|
/>
|
2018-11-30 01:24:02 +08:00
|
|
|
</div>
|
2019-05-09 03:13:05 +08:00
|
|
|
</Modal>
|
2018-11-30 01:24:02 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(withModalMounter(ExternalVideoModal));
|