2017-05-03 02:04:16 +02:00
|
|
|
import React from 'react';
|
2017-04-13 15:04:18 +02:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-04-21 20:05:35 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2019-05-03 16:16:30 +02:00
|
|
|
import Video from 'mastodon/features/video';
|
2017-05-03 02:04:16 +02:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2019-05-03 16:16:30 +02:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
|
|
|
|
export const previewState = 'previewVideoModal';
|
2017-04-13 15:04:18 +02:00
|
|
|
|
2017-06-23 19:36:54 +02:00
|
|
|
export default class VideoModal extends ImmutablePureComponent {
|
2017-04-13 15:04:18 +02:00
|
|
|
|
2017-05-12 14:44:10 +02:00
|
|
|
static propTypes = {
|
|
|
|
media: ImmutablePropTypes.map.isRequired,
|
2019-05-03 16:16:30 +02:00
|
|
|
status: ImmutablePropTypes.map,
|
2017-05-12 14:44:10 +02:00
|
|
|
time: PropTypes.number,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2019-05-03 16:16:30 +02:00
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
if (this.context.router) {
|
|
|
|
const history = this.context.router.history;
|
|
|
|
|
|
|
|
history.push(history.location.pathname, previewState);
|
|
|
|
|
|
|
|
this.unlistenHistory = history.listen(() => {
|
|
|
|
this.props.onClose();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
if (this.context.router) {
|
|
|
|
this.unlistenHistory();
|
|
|
|
|
|
|
|
if (this.context.router.history.location.state === previewState) {
|
|
|
|
this.context.router.history.goBack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleStatusClick = e => {
|
|
|
|
if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.context.router.history.push(`/statuses/${this.props.status.get('id')}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-13 15:04:18 +02:00
|
|
|
render () {
|
2019-05-03 16:16:30 +02:00
|
|
|
const { media, status, time, onClose } = this.props;
|
|
|
|
|
|
|
|
const link = status && <a href={status.get('url')} onClick={this.handleStatusClick}><FormattedMessage id='lightbox.view_context' defaultMessage='View context' /></a>;
|
2017-04-13 15:04:18 +02:00
|
|
|
|
|
|
|
return (
|
2018-03-04 20:32:24 +01:00
|
|
|
<div className='modal-root__modal video-modal'>
|
2017-04-13 15:04:18 +02:00
|
|
|
<div>
|
2017-09-14 03:39:10 +02:00
|
|
|
<Video
|
|
|
|
preview={media.get('preview_url')}
|
2019-04-27 03:24:09 +02:00
|
|
|
blurhash={media.get('blurhash')}
|
2017-09-14 03:39:10 +02:00
|
|
|
src={media.get('url')}
|
|
|
|
startTime={time}
|
|
|
|
onCloseVideo={onClose}
|
2019-05-03 16:16:30 +02:00
|
|
|
link={link}
|
2017-12-09 00:55:58 +01:00
|
|
|
detailed
|
2018-09-13 20:31:59 +02:00
|
|
|
alt={media.get('description')}
|
2017-09-14 03:39:10 +02:00
|
|
|
/>
|
2017-04-13 15:04:18 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-21 20:05:35 +02:00
|
|
|
}
|