2020-03-27 13:59:38 -07:00
|
|
|
import React from 'react';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import PropTypes from 'prop-types';
|
2020-05-28 15:52:07 -07:00
|
|
|
import Video from 'soapbox/features/video';
|
2020-03-27 13:59:38 -07:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
|
|
|
|
export const previewState = 'previewVideoModal';
|
|
|
|
|
|
|
|
export default class VideoModal extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
media: ImmutablePropTypes.map.isRequired,
|
|
|
|
status: ImmutablePropTypes.map,
|
2021-04-02 15:01:39 -07:00
|
|
|
account: ImmutablePropTypes.map,
|
2020-03-27 13:59:38 -07:00
|
|
|
time: PropTypes.number,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
2020-04-14 14:47:35 -07:00
|
|
|
componentDidMount() {
|
2020-03-27 13:59:38 -07:00
|
|
|
if (this.context.router) {
|
|
|
|
const history = this.context.router.history;
|
|
|
|
|
|
|
|
history.push(history.location.pathname, previewState);
|
|
|
|
|
|
|
|
this.unlistenHistory = history.listen(() => {
|
|
|
|
this.props.onClose();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 14:47:35 -07:00
|
|
|
componentWillUnmount() {
|
2020-03-27 13:59:38 -07:00
|
|
|
if (this.context.router) {
|
|
|
|
this.unlistenHistory();
|
|
|
|
|
|
|
|
if (this.context.router.history.location.state === previewState) {
|
|
|
|
this.context.router.history.goBack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleStatusClick = e => {
|
2021-04-02 15:01:39 -07:00
|
|
|
const { status, account } = this.props;
|
2020-03-27 13:59:38 -07:00
|
|
|
if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
|
|
|
|
e.preventDefault();
|
2021-04-02 15:01:39 -07:00
|
|
|
this.context.router.history.push(`/@${account.get('acct')}/posts/${status.get('id')}`);
|
2020-03-27 13:59:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 14:47:35 -07:00
|
|
|
render() {
|
2021-04-02 15:01:39 -07:00
|
|
|
const { media, status, account, time, onClose } = this.props;
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2021-04-02 15:01:39 -07:00
|
|
|
const link = status && account && <a href={status.get('url')} onClick={this.handleStatusClick}><FormattedMessage id='lightbox.view_context' defaultMessage='View context' /></a>;
|
2020-03-27 13:59:38 -07:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='modal-root__modal video-modal'>
|
|
|
|
<div>
|
|
|
|
<Video
|
|
|
|
preview={media.get('preview_url')}
|
|
|
|
blurhash={media.get('blurhash')}
|
|
|
|
src={media.get('url')}
|
|
|
|
startTime={time}
|
|
|
|
onCloseVideo={onClose}
|
|
|
|
link={link}
|
|
|
|
detailed
|
|
|
|
alt={media.get('description')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|