|
|
@ -9,7 +9,26 @@ import classNames from 'classnames';
|
|
|
|
import { autoPlayGif } from 'flavours/glitch/util/initial_state';
|
|
|
|
import { autoPlayGif } from 'flavours/glitch/util/initial_state';
|
|
|
|
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
const messages = defineMessages({
|
|
|
|
toggle_visible: { id: 'media_gallery.toggle_visible', defaultMessage: 'Toggle visibility' },
|
|
|
|
hidden: {
|
|
|
|
|
|
|
|
defaultMessage: 'Media hidden',
|
|
|
|
|
|
|
|
id: 'status.media_hidden',
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
sensitive: {
|
|
|
|
|
|
|
|
defaultMessage: 'Sensitive',
|
|
|
|
|
|
|
|
id: 'media_gallery.sensitive',
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
toggle: {
|
|
|
|
|
|
|
|
defaultMessage: 'Click to view',
|
|
|
|
|
|
|
|
id: 'status.sensitive_toggle',
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
toggle_visible: {
|
|
|
|
|
|
|
|
defaultMessage: 'Toggle visibility',
|
|
|
|
|
|
|
|
id: 'media_gallery.toggle_visible',
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
warning: {
|
|
|
|
|
|
|
|
defaultMessage: 'Sensitive content',
|
|
|
|
|
|
|
|
id: 'status.sensitive_warning',
|
|
|
|
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
class Item extends React.PureComponent {
|
|
|
|
class Item extends React.PureComponent {
|
|
|
@ -206,48 +225,79 @@ export default class MediaGallery extends React.PureComponent {
|
|
|
|
this.props.onOpenMedia(this.props.media, index);
|
|
|
|
this.props.onOpenMedia(this.props.media, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
isStandaloneEligible() {
|
|
|
|
|
|
|
|
const { media, standalone } = this.props;
|
|
|
|
|
|
|
|
return standalone && media.size === 1 && media.getIn([0, 'meta', 'small', 'aspect']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
render () {
|
|
|
|
render () {
|
|
|
|
const { media, intl, sensitive, letterbox, fullwidth } = this.props;
|
|
|
|
const {
|
|
|
|
|
|
|
|
handleClick,
|
|
|
|
|
|
|
|
handleOpen,
|
|
|
|
|
|
|
|
} = this;
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
|
|
|
fullwidth,
|
|
|
|
|
|
|
|
intl,
|
|
|
|
|
|
|
|
letterbox,
|
|
|
|
|
|
|
|
media,
|
|
|
|
|
|
|
|
sensitive,
|
|
|
|
|
|
|
|
standalone,
|
|
|
|
|
|
|
|
} = this.props;
|
|
|
|
const { visible } = this.state;
|
|
|
|
const { visible } = this.state;
|
|
|
|
const size = media.take(4).size;
|
|
|
|
const size = media.take(4).size;
|
|
|
|
|
|
|
|
const computedClass = classNames('media-gallery', `size-${size}`, { 'full-width': fullwidth });
|
|
|
|
|
|
|
|
|
|
|
|
let children;
|
|
|
|
return (
|
|
|
|
|
|
|
|
<div className={computedClass}>
|
|
|
|
if (!visible) {
|
|
|
|
{visible ? (
|
|
|
|
let warning;
|
|
|
|
<div className='sensitive-info'>
|
|
|
|
|
|
|
|
<IconButton
|
|
|
|
if (sensitive) {
|
|
|
|
icon='eye'
|
|
|
|
warning = <FormattedMessage id='status.sensitive_warning' defaultMessage='Sensitive content' />;
|
|
|
|
onClick={handleOpen}
|
|
|
|
} else {
|
|
|
|
overlay
|
|
|
|
warning = <FormattedMessage id='status.media_hidden' defaultMessage='Media hidden' />;
|
|
|
|
title={intl.formatMessage(messages.toggle_visible)}
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
|
|
|
|
{sensitive ? (
|
|
|
|
children = (
|
|
|
|
<span className='sensitive-marker'>
|
|
|
|
<button className='media-spoiler' onClick={this.handleOpen}>
|
|
|
|
<FormattedMessage {...messages.sensitive} />
|
|
|
|
<span className='media-spoiler__warning'>{warning}</span>
|
|
|
|
</span>
|
|
|
|
<span className='media-spoiler__trigger'><FormattedMessage id='status.sensitive_toggle' defaultMessage='Click to view' /></span>
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
{function () {
|
|
|
|
|
|
|
|
switch (true) {
|
|
|
|
|
|
|
|
case !visible:
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
|
|
|
className='media-spoiler'
|
|
|
|
|
|
|
|
onClick={handleOpen}
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<span className='media-spoiler__warning'>
|
|
|
|
|
|
|
|
<FormattedMessage {...(sensitive ? messages.warning : messages.hidden)} />
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<span className='media-spoiler__trigger'>
|
|
|
|
|
|
|
|
<FormattedMessage {...messages.toggle} />
|
|
|
|
|
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
case standalone && media.size === 1 && !!media.getIn([0, 'meta', 'small', 'aspect']):
|
|
|
|
if (this.isStandaloneEligible()) {
|
|
|
|
|
|
|
|
children = <Item standalone onClick={this.handleClick} attachment={media.get(0)} />;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
children = media.take(4).map((attachment, i) => <Item key={attachment.get('id')} onClick={this.handleClick} attachment={attachment} index={i} size={size} letterbox={letterbox} />);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className={`media-gallery size-${size} ${fullwidth ? 'full-width' : ''}`}>
|
|
|
|
<Item
|
|
|
|
<div className={classNames('spoiler-button', { 'spoiler-button--visible': visible })}>
|
|
|
|
attachment={media.get(0)}
|
|
|
|
<IconButton title={intl.formatMessage(messages.toggle_visible)} icon={visible ? 'eye' : 'eye-slash'} overlay onClick={this.handleOpen} />
|
|
|
|
onClick={handleClick}
|
|
|
|
</div>
|
|
|
|
standalone
|
|
|
|
|
|
|
|
/>
|
|
|
|
{children}
|
|
|
|
);
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return media.take(4).map(
|
|
|
|
|
|
|
|
(attachment, i) => (
|
|
|
|
|
|
|
|
<Item
|
|
|
|
|
|
|
|
attachment={attachment}
|
|
|
|
|
|
|
|
index={i}
|
|
|
|
|
|
|
|
key={attachment.get('id')}
|
|
|
|
|
|
|
|
letterbox={letterbox}
|
|
|
|
|
|
|
|
onClick={handleClick}
|
|
|
|
|
|
|
|
size={size}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|