gab-social/app/javascript/gabsocial/components/modal/video_modal.js

74 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-03-27 22:57:03 +00:00
import ImmutablePropTypes from 'react-immutable-proptypes'
import ImmutablePureComponent from 'react-immutable-pure-component'
import { FormattedMessage } from 'react-intl'
import Video from '../video'
2020-03-27 22:57:03 +00:00
export const previewState = 'previewVideoModal'
2019-07-02 08:10:25 +01:00
export default class VideoModal extends ImmutablePureComponent {
static propTypes = {
media: ImmutablePropTypes.map.isRequired,
status: ImmutablePropTypes.map,
time: PropTypes.number,
onClose: PropTypes.func.isRequired,
2020-03-27 22:57:03 +00:00
}
2019-07-02 08:10:25 +01:00
static contextTypes = {
router: PropTypes.object,
2020-03-27 22:57:03 +00:00
}
2019-07-02 08:10:25 +01:00
componentDidMount () {
if (this.context.router) {
2020-03-27 22:57:03 +00:00
const history = this.context.router.history
2019-07-02 08:10:25 +01:00
2020-03-27 22:57:03 +00:00
history.push(history.location.pathname, previewState)
2019-07-02 08:10:25 +01:00
this.unlistenHistory = history.listen(() => {
2020-03-27 22:57:03 +00:00
this.props.onClose()
})
2019-07-02 08:10:25 +01:00
}
}
componentWillUnmount () {
if (this.context.router) {
2020-03-27 22:57:03 +00:00
this.unlistenHistory()
2019-07-02 08:10:25 +01:00
if (this.context.router.history.location.state === previewState) {
2020-03-27 22:57:03 +00:00
this.context.router.history.goBack()
2019-07-02 08:10:25 +01:00
}
}
}
handleStatusClick = e => {
if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
2020-03-27 22:57:03 +00:00
e.preventDefault()
this.context.router.history.push(`/${this.props.status.getIn(['account', 'acct'])}/posts/${this.props.status.get('id')}`)
2019-07-02 08:10:25 +01:00
}
}
render () {
2020-03-27 22:57:03 +00:00
const { media, status, time, onClose } = this.props
2019-07-02 08:10:25 +01:00
2020-03-27 22:57:03 +00:00
const link = status && <a href={status.get('url')} onClick={this.handleStatusClick}><FormattedMessage id='lightbox.view_context' defaultMessage='View context' /></a>
2019-07-02 08:10:25 +01: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>
2020-03-27 22:57:03 +00:00
)
2019-07-02 08:10:25 +01:00
}
}