Pull displayMedia from Redux store

This commit is contained in:
Alex Gleason 2020-05-28 20:36:39 -05:00
parent ac341f0c2e
commit 183c6538ca
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
7 changed files with 81 additions and 66 deletions

View file

@ -14,7 +14,7 @@ const defaultSettings = ImmutableMap({
skinTone: 1, skinTone: 1,
reduceMotion: false, reduceMotion: false,
autoPlayGif: true, autoPlayGif: true,
displayMedia: true, displayMedia: 'default',
expandSpoilers: false, expandSpoilers: false,
unfollowModal: false, unfollowModal: false,
boostModal: false, boostModal: false,

View file

@ -7,7 +7,6 @@ import IconButton from './icon_button';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { isIOS } from '../is_mobile'; import { isIOS } from '../is_mobile';
import classNames from 'classnames'; import classNames from 'classnames';
import { displayMedia } from '../initial_state';
import { decode } from 'blurhash'; import { decode } from 'blurhash';
import { isPanoramic, isPortrait, isNonConformingRatio, minimumAspectRatio, maximumAspectRatio } from '../utils/media_aspect_ratio'; import { isPanoramic, isPortrait, isNonConformingRatio, minimumAspectRatio, maximumAspectRatio } from '../utils/media_aspect_ratio';
import { Map as ImmutableMap } from 'immutable'; import { Map as ImmutableMap } from 'immutable';
@ -17,11 +16,11 @@ const messages = defineMessages({
toggle_visible: { id: 'media_gallery.toggle_visible', defaultMessage: 'Toggle visibility' }, toggle_visible: { id: 'media_gallery.toggle_visible', defaultMessage: 'Toggle visibility' },
}); });
const mapStateToProps = state => ({ const mapStateToItemProps = state => ({
autoPlayGif: getSettings(state).get('autoPlayGif'), autoPlayGif: getSettings(state).get('autoPlayGif'),
}); });
@connect(mapStateToProps) @connect(mapStateToItemProps)
class Item extends React.PureComponent { class Item extends React.PureComponent {
static propTypes = { static propTypes = {
@ -238,7 +237,12 @@ class Item extends React.PureComponent {
} }
export default @injectIntl const mapStateToMediaGalleryProps = state => ({
displayMedia: getSettings(state).get('displayMedia'),
});
export default @connect(mapStateToMediaGalleryProps)
@injectIntl
class MediaGallery extends React.PureComponent { class MediaGallery extends React.PureComponent {
static propTypes = { static propTypes = {
@ -253,6 +257,7 @@ class MediaGallery extends React.PureComponent {
cacheWidth: PropTypes.func, cacheWidth: PropTypes.func,
visible: PropTypes.bool, visible: PropTypes.bool,
onToggleVisibility: PropTypes.func, onToggleVisibility: PropTypes.func,
displayMedia: PropTypes.string,
}; };
static defaultProps = { static defaultProps = {
@ -260,11 +265,12 @@ class MediaGallery extends React.PureComponent {
}; };
state = { state = {
visible: this.props.visible !== undefined ? this.props.visible : (displayMedia !== 'hide_all' && !this.props.sensitive || displayMedia === 'show_all'), visible: this.props.visible !== undefined ? this.props.visible : (this.props.displayMedia !== 'hide_all' && !this.props.sensitive || this.props.displayMedia === 'show_all'),
width: this.props.defaultWidth, width: this.props.defaultWidth,
}; };
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
const { displayMedia } = this.props;
if (!is(nextProps.media, this.props.media) && nextProps.visible === undefined) { if (!is(nextProps.media, this.props.media) && nextProps.visible === undefined) {
this.setState({ visible: displayMedia !== 'hide_all' && !nextProps.sensitive || displayMedia === 'show_all' }); this.setState({ visible: displayMedia !== 'hide_all' && !nextProps.sensitive || displayMedia === 'show_all' });
} else if (!is(nextProps.visible, this.props.visible) && nextProps.visible !== undefined) { } else if (!is(nextProps.visible, this.props.visible) && nextProps.visible !== undefined) {

View file

@ -17,7 +17,6 @@ import { HotKeys } from 'react-hotkeys';
import classNames from 'classnames'; import classNames from 'classnames';
import Icon from 'soapbox/components/icon'; import Icon from 'soapbox/components/icon';
import PollContainer from 'soapbox/containers/poll_container'; import PollContainer from 'soapbox/containers/poll_container';
import { displayMedia } from '../initial_state';
import { NavLink } from 'react-router-dom'; import { NavLink } from 'react-router-dom';
// We use the component (and not the container) since we do not want // We use the component (and not the container) since we do not want
@ -41,7 +40,7 @@ export const textForScreenReader = (intl, status, rebloggedByText = false) => {
return values.join(', '); return values.join(', ');
}; };
export const defaultMediaVisibility = (status) => { export const defaultMediaVisibility = (status, displayMedia) => {
if (!status) { if (!status) {
return undefined; return undefined;
} }
@ -89,6 +88,7 @@ class Status extends ImmutablePureComponent {
cacheMediaWidth: PropTypes.func, cacheMediaWidth: PropTypes.func,
cachedMediaWidth: PropTypes.number, cachedMediaWidth: PropTypes.number,
group: ImmutablePropTypes.map, group: ImmutablePropTypes.map,
displayMedia: PropTypes.string,
}; };
// Avoid checking props that are functions (and whose equality will always // Avoid checking props that are functions (and whose equality will always
@ -101,7 +101,7 @@ class Status extends ImmutablePureComponent {
]; ];
state = { state = {
showMedia: defaultMediaVisibility(this.props.status), showMedia: defaultMediaVisibility(this.props.status, this.props.displayMedia),
statusId: undefined, statusId: undefined,
}; };

View file

@ -50,6 +50,7 @@ const makeMapStateToProps = () => {
const mapStateToProps = (state, props) => ({ const mapStateToProps = (state, props) => ({
status: getStatus(state, props), status: getStatus(state, props),
displayMedia: getSettings(state).get('displayMedia'),
}); });
return mapStateToProps; return mapStateToProps;

View file

@ -4,7 +4,6 @@ import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component'; import ImmutablePureComponent from 'react-immutable-pure-component';
import Icon from 'soapbox/components/icon'; import Icon from 'soapbox/components/icon';
import { displayMedia } from 'soapbox/initial_state';
import classNames from 'classnames'; import classNames from 'classnames';
import { decode } from 'blurhash'; import { decode } from 'blurhash';
import { isIOS } from 'soapbox/is_mobile'; import { isIOS } from 'soapbox/is_mobile';
@ -12,6 +11,7 @@ import { getSettings } from 'soapbox/actions/settings';
const mapStateToProps = state => ({ const mapStateToProps = state => ({
autoPlayGif: getSettings(state).get('autoPlayGif'), autoPlayGif: getSettings(state).get('autoPlayGif'),
displayMedia: getSettings(state).get('displayMedia'),
}); });
export default @connect(mapStateToProps) export default @connect(mapStateToProps)
@ -22,10 +22,11 @@ class MediaItem extends ImmutablePureComponent {
displayWidth: PropTypes.number.isRequired, displayWidth: PropTypes.number.isRequired,
onOpenMedia: PropTypes.func.isRequired, onOpenMedia: PropTypes.func.isRequired,
autoPlayGif: PropTypes.bool, autoPlayGif: PropTypes.bool,
displayMedia: PropTypes.string,
}; };
state = { state = {
visible: displayMedia !== 'hide_all' && !this.props.attachment.getIn(['status', 'sensitive']) || displayMedia === 'show_all', visible: this.props.displayMedia !== 'hide_all' && !this.props.attachment.getIn(['status', 'sensitive']) || this.props.displayMedia === 'show_all',
loaded: false, loaded: false,
}; };

View file

@ -1,14 +1,15 @@
import React from 'react'; import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { fromJS, is } from 'immutable'; import { fromJS, is } from 'immutable';
import { throttle } from 'lodash'; import { throttle } from 'lodash';
import classNames from 'classnames'; import classNames from 'classnames';
import { isFullscreen, requestFullscreen, exitFullscreen } from '../ui/util/fullscreen'; import { isFullscreen, requestFullscreen, exitFullscreen } from '../ui/util/fullscreen';
import { displayMedia } from '../../initial_state';
import Icon from 'soapbox/components/icon'; import Icon from 'soapbox/components/icon';
import { decode } from 'blurhash'; import { decode } from 'blurhash';
import { isPanoramic, isPortrait, minimumAspectRatio, maximumAspectRatio } from '../../utils/media_aspect_ratio'; import { isPanoramic, isPortrait, minimumAspectRatio, maximumAspectRatio } from '../../utils/media_aspect_ratio';
import { getSettings } from 'soapbox/actions/settings';
const messages = defineMessages({ const messages = defineMessages({
play: { id: 'video.play', defaultMessage: 'Play' }, play: { id: 'video.play', defaultMessage: 'Play' },
@ -87,7 +88,12 @@ export const getPointerPosition = (el, event) => {
return position; return position;
}; };
export default @injectIntl const mapStateToProps = state => ({
displayMedia: getSettings(state).get('displayMedia'),
});
export default @connect(mapStateToProps)
@injectIntl
class Video extends React.PureComponent { class Video extends React.PureComponent {
static propTypes = { static propTypes = {
@ -109,6 +115,7 @@ class Video extends React.PureComponent {
blurhash: PropTypes.string, blurhash: PropTypes.string,
link: PropTypes.node, link: PropTypes.node,
aspectRatio: PropTypes.number, aspectRatio: PropTypes.number,
displayMedia: PropTypes.string,
}; };
state = { state = {
@ -121,7 +128,7 @@ class Video extends React.PureComponent {
fullscreen: false, fullscreen: false,
hovered: false, hovered: false,
muted: false, muted: false,
revealed: this.props.visible !== undefined ? this.props.visible : (displayMedia !== 'hide_all' && !this.props.sensitive || displayMedia === 'show_all'), revealed: this.props.visible !== undefined ? this.props.visible : (this.props.displayMedia !== 'hide_all' && !this.props.sensitive || this.props.displayMedia === 'show_all'),
}; };
// hard coded in components.scss // hard coded in components.scss

View file

@ -363,7 +363,7 @@ If it's not documented, it's because I inherited it from Mastodon and I don't kn
``` ```
settings: { settings: {
autoPlayGif: true, autoPlayGif: true,
displayMedia: true, displayMedia: 'default',
deleteModal: true, deleteModal: true,
unfollowModal: false, unfollowModal: false,
frequentlyUsedEmojis: { frequentlyUsedEmojis: {