You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.9 KiB

  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import Video from 'mastodon/features/video';
  5. import ImmutablePureComponent from 'react-immutable-pure-component';
  6. export const previewState = 'previewVideoModal';
  7. export default class VideoModal extends ImmutablePureComponent {
  8. static propTypes = {
  9. media: ImmutablePropTypes.map.isRequired,
  10. statusId: PropTypes.string,
  11. options: PropTypes.shape({
  12. startTime: PropTypes.number,
  13. autoPlay: PropTypes.bool,
  14. defaultVolume: PropTypes.number,
  15. }),
  16. onClose: PropTypes.func.isRequired,
  17. };
  18. static contextTypes = {
  19. router: PropTypes.object,
  20. };
  21. componentDidMount () {
  22. if (this.context.router) {
  23. const history = this.context.router.history;
  24. history.push(history.location.pathname, previewState);
  25. this.unlistenHistory = history.listen(() => {
  26. this.props.onClose();
  27. });
  28. }
  29. }
  30. componentWillUnmount () {
  31. if (this.context.router) {
  32. this.unlistenHistory();
  33. if (this.context.router.history.location.state === previewState) {
  34. this.context.router.history.goBack();
  35. }
  36. }
  37. }
  38. render () {
  39. const { media, onClose } = this.props;
  40. const options = this.props.options || {};
  41. return (
  42. <div className='modal-root__modal video-modal'>
  43. <div className='video-modal__container'>
  44. <Video
  45. preview={media.get('preview_url')}
  46. frameRate={media.getIn(['meta', 'original', 'frame_rate'])}
  47. blurhash={media.get('blurhash')}
  48. src={media.get('url')}
  49. currentTime={options.startTime}
  50. autoPlay={options.autoPlay}
  51. volume={options.defaultVolume}
  52. onCloseVideo={onClose}
  53. detailed
  54. alt={media.get('description')}
  55. />
  56. </div>
  57. </div>
  58. );
  59. }
  60. }