diff options
author | Claire <claire.github-309c@sitedethib.com> | 2021-05-08 00:37:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-08 00:37:51 +0200 |
commit | 5233e9910677c921ab93e0997964144b1df95a63 (patch) | |
tree | bab0d925ffe45724fb234477ee9c3a8c24886646 /app/javascript/flavours/glitch/containers/media_container.js | |
parent | df82963ea4fda69571ae27abef4239d4b755eb2f (diff) | |
parent | 196cef8977a8dacd56ee910cd9d482faae23047c (diff) |
Merge pull request #1531 from ClearlyClaire/glitch-soc/features/upstream-media-modal
Port upstream's new media modal
Diffstat (limited to 'app/javascript/flavours/glitch/containers/media_container.js')
-rw-r--r-- | app/javascript/flavours/glitch/containers/media_container.js | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/app/javascript/flavours/glitch/containers/media_container.js b/app/javascript/flavours/glitch/containers/media_container.js index a483510b0..8657b8064 100644 --- a/app/javascript/flavours/glitch/containers/media_container.js +++ b/app/javascript/flavours/glitch/containers/media_container.js @@ -2,7 +2,7 @@ import React, { PureComponent, Fragment } from 'react'; 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'; @@ -30,6 +30,8 @@ export default class MediaContainer extends PureComponent { media: null, index: null, time: null, + backgroundColor: null, + options: null, }; handleOpenMedia = (media, index) => { @@ -39,20 +41,32 @@ export default class MediaContainer extends PureComponent { 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 = () => { document.body.classList.remove('with-modals--active'); document.documentElement.style.marginRight = 0; - this.setState({ media: null, index: null, time: null }); + this.setState({ + media: null, + index: null, + time: null, + backgroundColor: null, + options: null, + }); + } + + setBackgroundColor = color => { + this.setState({ backgroundColor: color }); } render () { @@ -73,6 +87,7 @@ export default class MediaContainer extends PureComponent { ...(hashtag ? { hashtag: fromJS(hashtag) } : {}), ...(componentName === 'Video' ? { + componetIndex: i, onOpenVideo: this.handleOpenVideo, } : { onOpenMedia: this.handleOpenMedia, @@ -85,13 +100,16 @@ export default class MediaContainer extends PureComponent { ); })} - <ModalRoot onClose={this.handleCloseMedia}> + <ModalRoot backgroundColor={this.state.backgroundColor} onClose={this.handleCloseMedia}> {this.state.media && ( <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} /> )} </ModalRoot> |