prevent handleAutoplay in componentDidUpdate

This commit is contained in:
Travis Eden 2018-07-18 10:41:14 -04:00
parent 17ca490db4
commit bc68b75012

View file

@ -17,6 +17,9 @@ type Props = {
download_path: string,
completed: boolean,
},
fileInfoErrors: ?{
[string]: boolean,
},
metadata: ?{
nsfw: boolean,
thumbnail: string,
@ -55,14 +58,17 @@ class FileViewer extends React.PureComponent<Props> {
window.addEventListener('keydown', this.handleKeyDown);
}
componentWillReceiveProps(nextProps: Props) {
componentDidUpdate(prev: Props) {
if (
this.props.autoplay !== nextProps.autoplay ||
this.props.fileInfo !== nextProps.fileInfo ||
this.props.isDownloading !== nextProps.isDownloading ||
this.props.playingUri !== nextProps.playingUri
this.props.autoplay !== prev.autoplay ||
this.props.fileInfo !== prev.fileInfo ||
this.props.isDownloading !== prev.isDownloading ||
this.props.playingUri !== prev.playingUri
) {
this.handleAutoplay(nextProps);
// suppress autoplay after download error
if (!(this.props.uri in this.props.fileInfoErrors)) {
this.handleAutoplay(this.props);
}
}
}
@ -79,22 +85,10 @@ class FileViewer extends React.PureComponent<Props> {
}
}
// do not play when state.content.errors[uri]
handleAutoplay = (props: Props) => {
const {
autoplay,
playingUri,
fileInfo,
costInfo,
isDownloading,
uri,
play,
metadata,
fileInfoErrors,
} = props;
const { autoplay, playingUri, fileInfo, costInfo, isDownloading, uri, play, metadata } = props;
const playable =
autoplay && playingUri !== uri && metadata && !metadata.nsfw && !(uri in fileInfoErrors);
const playable = autoplay && playingUri !== uri && metadata && !metadata.nsfw;
if (playable && costInfo && costInfo.cost === 0 && !fileInfo && !isDownloading) {
play(uri);