fix nsfw conditions

This commit is contained in:
Travis Eden 2018-05-11 10:33:33 -04:00
parent bf8518d04c
commit 4deee1573d

View file

@ -19,6 +19,7 @@ type Props = {
nsfw: boolean, nsfw: boolean,
thumbnail: string, thumbnail: string,
}, },
autoplay: boolean,
isLoading: boolean, isLoading: boolean,
isDownloading: boolean, isDownloading: boolean,
playingUri: ?string, playingUri: ?string,
@ -34,56 +35,38 @@ type Props = {
mediaPosition: ?number, mediaPosition: ?number,
className: ?string, className: ?string,
obscureNsfw: boolean, obscureNsfw: boolean,
play: string => void play: string => void,
}; };
class Video extends React.PureComponent<Props> { class Video extends React.PureComponent<Props> {
componentWillUnmount() {
this.props.cancelPlay();
}
componentDidMount() { componentDidMount() {
this.handleAutoplay(this.props); this.handleAutoplay(this.props);
} }
componentWillReceiveProps(nextProps: Props) { componentWillReceiveProps(nextProps: Props) {
this.handleAutoplay(nextProps); if (
this.props.autoplay !== nextProps.autoplay ||
this.props.fileInfo !== nextProps.fileInfo ||
this.props.isDownloading !== nextProps.isDownloading ||
this.props.playingUri !== nextProps.playingUri
) {
this.handleAutoplay(nextProps);
}
}
componentWillUnmount() {
this.props.cancelPlay();
} }
handleAutoplay(props: Props) { handleAutoplay(props: Props) {
const { const { autoplay, playingUri, fileInfo, costInfo, isDownloading, uri, load, play, metadata } = props;
autoplay,
obscureNsfw,
playingUri,
fileInfo,
costInfo,
isDownloading,
uri,
load,
play
} = props;
const playable = ( const playable = autoplay && playingUri !== uri && metadata && !metadata.nsfw;
autoplay &&
obscureNsfw === false &&
playingUri !== uri
);
if ( if (playable && costInfo && costInfo.cost === 0 && !fileInfo && !isDownloading) {
playable &&
costInfo &&
costInfo.cost === 0 &&
!fileInfo &&
!isDownloading
) {
load(uri); load(uri);
play(uri); play(uri);
} } else if (playable && fileInfo && fileInfo.blobs_completed > 0) {
else if (
playable &&
fileInfo &&
fileInfo.blobs_completed > 0
) {
play(uri); play(uri);
} }
} }
@ -137,7 +120,8 @@ class Video extends React.PureComponent<Props> {
const poster = metadata && metadata.thumbnail; const poster = metadata && metadata.thumbnail;
const layoverClass = classnames('content__cover', { 'card__media--nsfw': shouldObscureNsfw }); const layoverClass = classnames('content__cover', { 'card__media--nsfw': shouldObscureNsfw });
const layoverStyle = !shouldObscureNsfw && poster ? { backgroundImage: `url("${poster}")` } : {}; const layoverStyle =
!shouldObscureNsfw && poster ? { backgroundImage: `url("${poster}")` } : {};
return ( return (
<div className={classnames('video', {}, className)}> <div className={classnames('video', {}, className)}>
@ -147,7 +131,7 @@ class Video extends React.PureComponent<Props> {
<div className={layoverClass} style={layoverStyle}> <div className={layoverClass} style={layoverStyle}>
<LoadingScreen status={loadStatusMessage} /> <LoadingScreen status={loadStatusMessage} />
</div> </div>
) : ( ) : (
<VideoPlayer <VideoPlayer
filename={fileInfo.file_name} filename={fileInfo.file_name}
poster={poster} poster={poster}