import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import { IntlProvider, addLocaleData } from 'react-intl';
-import { List as ImmutableList, fromJS } from 'immutable';
+import { fromJS } from 'immutable';
import { getLocale } from 'mastodon/locales';
import { getScrollbarWidth } from 'flavours/glitch/util/scrollbar';
import MediaGallery from 'flavours/glitch/components/media_gallery';
index: null,
time: null,
backgroundColor: null,
+ options: null,
};
handleOpenMedia = (media, index) => {
this.setState({ media, index });
}
- handleOpenVideo = (video, time) => {
- const media = ImmutableList([video]);
+ handleOpenVideo = (options) => {
+ const { components } = this.props;
+ const { media } = JSON.parse(components[options.componetIndex].getAttribute('data-props'));
+ const mediaList = fromJS(media);
document.body.classList.add('with-modals--active');
document.documentElement.style.marginRight = `${getScrollbarWidth()}px`;
- this.setState({ media, time });
+ this.setState({ media: mediaList, options });
}
handleCloseMedia = () => {
index: null,
time: null,
backgroundColor: null,
+ options: null,
});
}
...(hashtag ? { hashtag: fromJS(hashtag) } : {}),
...(componentName === 'Video' ? {
+ componetIndex: i,
onOpenVideo: this.handleOpenVideo,
} : {
onOpenMedia: this.handleOpenMedia,
<MediaModal
media={this.state.media}
index={this.state.index || 0}
- time={this.state.time}
+ currentTime={this.state.options?.startTime}
+ autoPlay={this.state.options?.autoPlay}
+ volume={this.state.options?.defaultVolume}
onClose={this.handleCloseMedia}
onChangeBackgroundColor={this.setBackgroundColor}
/>
onClose: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
onChangeBackgroundColor: PropTypes.func.isRequired,
+ currentTime: PropTypes.number,
+ autoPlay: PropTypes.bool,
+ volume: PropTypes.number,
};
state = {
/>
);
} else if (image.get('type') === 'video') {
- const { time } = this.props;
+ const { currentTime, autoPlay, volume } = this.props;
return (
<Video
src={image.get('url')}
width={image.get('width')}
height={image.get('height')}
- currentTime={time || 0}
+ frameRate={image.getIn(['meta', 'original', 'frame_rate'])}
+ currentTime={currentTime || 0}
+ autoPlay={autoPlay || false}
+ volume={volume || 1}
onCloseVideo={onClose}
detailed
alt={image.get('description')}
autoPlay: PropTypes.bool,
volume: PropTypes.number,
muted: PropTypes.bool,
+ componetIndex: PropTypes.number,
};
static defaultProps = {
startTime: this.video.currentTime,
autoPlay: !this.state.paused,
defaultVolume: this.state.volume,
+ componetIndex: this.props.componetIndex,
});
}