2019-01-16 04:44:41 +08:00
|
|
|
import React, { Component } from 'react';
|
2022-02-15 23:54:55 +08:00
|
|
|
import { withModalMounter } from '/imports/ui/components/common/modal/service';
|
2018-11-30 01:24:02 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2019-07-17 04:33:27 +08:00
|
|
|
import { isUrlValid } from '../service';
|
2021-11-04 01:01:50 +08:00
|
|
|
import Settings from '/imports/ui/services/settings';
|
|
|
|
import Styled 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;
|
2021-11-04 01:01:50 +08:00
|
|
|
const { animations } = Settings.application;
|
2019-01-15 03:10:08 +08:00
|
|
|
|
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
|
|
|
|
? (
|
2021-11-04 01:01:50 +08:00
|
|
|
<Styled.UrlError animations={animations}>
|
2019-01-16 04:44:41 +08:00
|
|
|
{intl.formatMessage(intlMessages.urlError)}
|
2021-11-04 01:01:50 +08:00
|
|
|
</Styled.UrlError>
|
2019-01-16 04:44:41 +08:00
|
|
|
)
|
|
|
|
: 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;
|
2021-11-04 01:01:50 +08:00
|
|
|
const { animations } = Settings.application;
|
2019-01-16 04:44:41 +08:00
|
|
|
|
2019-07-16 04:12:07 +08:00
|
|
|
const startDisabled = !isUrlValid(url);
|
2018-11-30 01:24:02 +08:00
|
|
|
|
|
|
|
return (
|
2021-11-04 01:01:50 +08:00
|
|
|
<Styled.ExternalVideoModal
|
2019-01-16 04:44:41 +08:00
|
|
|
onRequestClose={closeModal}
|
2019-05-09 03:13:05 +08:00
|
|
|
contentLabel={intl.formatMessage(intlMessages.title)}
|
2022-11-11 02:09:21 +08:00
|
|
|
title={intl.formatMessage(intlMessages.title)}
|
2018-11-30 01:24:02 +08:00
|
|
|
>
|
2021-11-04 01:01:50 +08:00
|
|
|
<Styled.Content>
|
|
|
|
<Styled.VideoUrl animations={animations}>
|
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
|
2023-03-10 03:44:47 +08:00
|
|
|
autoFocus
|
2019-01-16 04:44:41 +08:00
|
|
|
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"
|
2022-11-04 00:06:25 +08:00
|
|
|
onPaste={(e) => { e.stopPropagation(); }}
|
2022-11-04 03:24:00 +08:00
|
|
|
onCut={(e) => { e.stopPropagation(); }}
|
|
|
|
onCopy={(e) => { e.stopPropagation(); }}
|
2019-01-16 04:44:41 +08:00
|
|
|
/>
|
2018-11-30 01:24:02 +08:00
|
|
|
</label>
|
2021-11-04 01:01:50 +08:00
|
|
|
<Styled.ExternalVideoNote id="external-video-note">
|
2019-03-15 21:04:19 +08:00
|
|
|
{intl.formatMessage(intlMessages.note)}
|
2021-11-04 01:01:50 +08:00
|
|
|
</Styled.ExternalVideoNote>
|
|
|
|
</Styled.VideoUrl>
|
2018-11-30 01:24:02 +08:00
|
|
|
|
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
|
|
|
|
2021-11-04 01:01:50 +08:00
|
|
|
<Styled.StartButton
|
2019-04-25 01:19:35 +08:00
|
|
|
label={intl.formatMessage(intlMessages.start)}
|
|
|
|
onClick={this.startWatchingHandler}
|
|
|
|
disabled={startDisabled}
|
2022-01-20 21:03:18 +08:00
|
|
|
data-test="startNewVideo"
|
2022-06-07 01:33:15 +08:00
|
|
|
color="primary"
|
2019-01-16 04:44:41 +08:00
|
|
|
/>
|
2021-11-04 01:01:50 +08:00
|
|
|
</Styled.Content>
|
|
|
|
</Styled.ExternalVideoModal>
|
2018-11-30 01:24:02 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(withModalMounter(ExternalVideoModal));
|