Show visibility toggle on videos, show regardless of sensitivity

This commit is contained in:
blackle 2017-01-19 21:24:30 -05:00
parent c8e4b9c663
commit 7f63edd820
2 changed files with 71 additions and 32 deletions

View File

@ -49,7 +49,7 @@ const MediaGallery = React.createClass({
getInitialState () { getInitialState () {
return { return {
visible: false visible: !this.props.sensitive
}; };
}, },
@ -80,13 +80,22 @@ const MediaGallery = React.createClass({
let children; let children;
if (sensitive && !this.state.visible) { if (!this.state.visible) {
children = ( if (sensitive) {
<div style={spoilerStyle} onClick={this.handleOpen}> children = (
<span style={spoilerSpanStyle}><FormattedMessage id='status.sensitive_warning' defaultMessage='Sensitive content' /></span> <div style={spoilerStyle} onClick={this.handleOpen}>
<span style={spoilerSubSpanStyle}><FormattedMessage id='status.sensitive_toggle' defaultMessage='Click to view' /></span> <span style={spoilerSpanStyle}><FormattedMessage id='status.sensitive_warning' defaultMessage='Sensitive content' /></span>
</div> <span style={spoilerSubSpanStyle}><FormattedMessage id='status.sensitive_toggle' defaultMessage='Click to view' /></span>
); </div>
);
} else {
children = (
<div style={spoilerStyle} onClick={this.handleOpen}>
<span style={spoilerSpanStyle}><FormattedMessage id='status.media_hidden' defaultMessage='Media hidden' /></span>
<span style={spoilerSubSpanStyle}><FormattedMessage id='status.sensitive_toggle' defaultMessage='Click to view' /></span>
</div>
);
}
} else { } else {
const size = media.take(4).size; const size = media.take(4).size;
@ -148,19 +157,11 @@ const MediaGallery = React.createClass({
}); });
} }
let spoilerButton; return (
<div style={{ ...outerStyle, height: `${this.props.height}px` }}>
if (sensitive) {
spoilerButton = (
<div style={spoilerButtonStyle} > <div style={spoilerButtonStyle} >
<IconButton title={intl.formatMessage(messages.toggle_visible)} icon={this.state.visible ? 'eye' : 'eye-slash'} onClick={this.handleOpen} /> <IconButton title={intl.formatMessage(messages.toggle_visible)} icon={this.state.visible ? 'eye' : 'eye-slash'} onClick={this.handleOpen} />
</div> </div>
);
}
return (
<div style={{ ...outerStyle, height: `${this.props.height}px` }}>
{spoilerButton}
{children} {children}
</div> </div>
); );

View File

@ -4,7 +4,8 @@ import IconButton from './icon_button';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
const messages = defineMessages({ const messages = defineMessages({
toggle_sound: { id: 'video_player.toggle_sound', defaultMessage: 'Toggle sound' } toggle_sound: { id: 'video_player.toggle_sound', defaultMessage: 'Toggle sound' },
toggle_visible: { id: 'video_player.toggle_visible', defaultMessage: 'Toggle visibility' }
}); });
const videoStyle = { const videoStyle = {
@ -20,7 +21,7 @@ const videoStyle = {
const muteStyle = { const muteStyle = {
position: 'absolute', position: 'absolute',
top: '10px', top: '10px',
left: '10px', right: '10px',
opacity: '0.8', opacity: '0.8',
zIndex: '5' zIndex: '5'
}; };
@ -35,7 +36,8 @@ const spoilerStyle = {
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
flexDirection: 'column' flexDirection: 'column',
position: 'relative'
}; };
const spoilerSpanStyle = { const spoilerSpanStyle = {
@ -49,6 +51,13 @@ const spoilerSubSpanStyle = {
fontWeight: '500' fontWeight: '500'
}; };
const spoilerButtonStyle = {
position: 'absolute',
top: '6px',
left: '8px',
zIndex: '100'
};
const VideoPlayer = React.createClass({ const VideoPlayer = React.createClass({
propTypes: { propTypes: {
media: ImmutablePropTypes.map.isRequired, media: ImmutablePropTypes.map.isRequired,
@ -66,7 +75,8 @@ const VideoPlayer = React.createClass({
getInitialState () { getInitialState () {
return { return {
visible: false, visible: !this.props.sensitive,
preview: true,
muted: true muted: true
}; };
}, },
@ -90,22 +100,49 @@ const VideoPlayer = React.createClass({
}, },
handleOpen () { handleOpen () {
this.setState({ visible: true }); this.setState({ preview: !this.state.preview });
},
handleVisibility () {
this.setState({
visible: !this.state.visible,
preview: true
});
}, },
render () { render () {
const { media, intl, width, height, sensitive } = this.props; const { media, intl, width, height, sensitive } = this.props;
if (sensitive && !this.state.visible) { let spoilerButton = (
return ( <div style={spoilerButtonStyle} >
<div style={{...spoilerStyle, width: `${width}px`, height: `${height}px` }} onClick={this.handleOpen}> <IconButton title={intl.formatMessage(messages.toggle_visible)} icon={this.state.visible ? 'eye' : 'eye-slash'} onClick={this.handleVisibility} />
<span style={spoilerSpanStyle}><FormattedMessage id='status.sensitive_warning' defaultMessage='Sensitive content' /></span> </div>
<span style={spoilerSubSpanStyle}><FormattedMessage id='status.sensitive_toggle' defaultMessage='Click to view' /></span> );
</div>
); if (!this.state.visible) {
} else if (!sensitive && !this.state.visible) { if (sensitive) {
return (
<div style={{...spoilerStyle, width: `${width}px`, height: `${height}px` }} onClick={this.handleVisibility}>
{spoilerButton}
<span style={spoilerSpanStyle}><FormattedMessage id='status.sensitive_warning' defaultMessage='Sensitive content' /></span>
<span style={spoilerSubSpanStyle}><FormattedMessage id='status.sensitive_toggle' defaultMessage='Click to view' /></span>
</div>
);
} else {
return (
<div style={{...spoilerStyle, width: `${width}px`, height: `${height}px` }} onClick={this.handleOpen}>
{spoilerButton}
<span style={spoilerSpanStyle}><FormattedMessage id='status.media_hidden' defaultMessage='Media hidden' /></span>
<span style={spoilerSubSpanStyle}><FormattedMessage id='status.sensitive_toggle' defaultMessage='Click to view' /></span>
</div>
);
}
}
if (this.state.preview) {
return ( return (
<div style={{ cursor: 'pointer', position: 'relative', marginTop: '8px', width: `${width}px`, height: `${height}px`, background: `url(${media.get('preview_url')}) no-repeat center`, backgroundSize: 'cover' }} onClick={this.handleOpen}> <div style={{ cursor: 'pointer', position: 'relative', marginTop: '8px', width: `${width}px`, height: `${height}px`, background: `url(${media.get('preview_url')}) no-repeat center`, backgroundSize: 'cover' }} onClick={this.handleOpen}>
{spoilerButton}
<div style={{ position: 'absolute', top: '50%', left: '50%', fontSize: '36px', transform: 'translate(-50%, -50%)', padding: '5px', borderRadius: '100px', color: 'rgba(255, 255, 255, 0.8)' }}><i className='fa fa-play' /></div> <div style={{ position: 'absolute', top: '50%', left: '50%', fontSize: '36px', transform: 'translate(-50%, -50%)', padding: '5px', borderRadius: '100px', color: 'rgba(255, 255, 255, 0.8)' }}><i className='fa fa-play' /></div>
</div> </div>
); );
@ -113,6 +150,7 @@ const VideoPlayer = React.createClass({
return ( return (
<div style={{ cursor: 'default', marginTop: '8px', overflow: 'hidden', width: `${width}px`, height: `${height}px`, boxSizing: 'border-box', background: '#000', position: 'relative' }}> <div style={{ cursor: 'default', marginTop: '8px', overflow: 'hidden', width: `${width}px`, height: `${height}px`, boxSizing: 'border-box', background: '#000', position: 'relative' }}>
{spoilerButton}
<div style={muteStyle}><IconButton title={intl.formatMessage(messages.toggle_sound)} icon={this.state.muted ? 'volume-off' : 'volume-up'} onClick={this.handleClick} /></div> <div style={muteStyle}><IconButton title={intl.formatMessage(messages.toggle_sound)} icon={this.state.muted ? 'volume-off' : 'volume-up'} onClick={this.handleClick} /></div>
<video src={media.get('url')} autoPlay='true' loop={true} muted={this.state.muted} style={videoStyle} onClick={this.handleVideoClick} /> <video src={media.get('url')} autoPlay='true' loop={true} muted={this.state.muted} style={videoStyle} onClick={this.handleVideoClick} />
</div> </div>