prevent handleAutoplay in componentDidUpdate
This commit is contained in:
parent
17ca490db4
commit
bc68b75012
1 changed files with 14 additions and 20 deletions
|
@ -17,6 +17,9 @@ type Props = {
|
||||||
download_path: string,
|
download_path: string,
|
||||||
completed: boolean,
|
completed: boolean,
|
||||||
},
|
},
|
||||||
|
fileInfoErrors: ?{
|
||||||
|
[string]: boolean,
|
||||||
|
},
|
||||||
metadata: ?{
|
metadata: ?{
|
||||||
nsfw: boolean,
|
nsfw: boolean,
|
||||||
thumbnail: string,
|
thumbnail: string,
|
||||||
|
@ -55,14 +58,17 @@ class FileViewer extends React.PureComponent<Props> {
|
||||||
window.addEventListener('keydown', this.handleKeyDown);
|
window.addEventListener('keydown', this.handleKeyDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps: Props) {
|
componentDidUpdate(prev: Props) {
|
||||||
if (
|
if (
|
||||||
this.props.autoplay !== nextProps.autoplay ||
|
this.props.autoplay !== prev.autoplay ||
|
||||||
this.props.fileInfo !== nextProps.fileInfo ||
|
this.props.fileInfo !== prev.fileInfo ||
|
||||||
this.props.isDownloading !== nextProps.isDownloading ||
|
this.props.isDownloading !== prev.isDownloading ||
|
||||||
this.props.playingUri !== nextProps.playingUri
|
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) => {
|
handleAutoplay = (props: Props) => {
|
||||||
const {
|
const { autoplay, playingUri, fileInfo, costInfo, isDownloading, uri, play, metadata } = props;
|
||||||
autoplay,
|
|
||||||
playingUri,
|
|
||||||
fileInfo,
|
|
||||||
costInfo,
|
|
||||||
isDownloading,
|
|
||||||
uri,
|
|
||||||
play,
|
|
||||||
metadata,
|
|
||||||
fileInfoErrors,
|
|
||||||
} = props;
|
|
||||||
|
|
||||||
const playable =
|
const playable = autoplay && playingUri !== uri && metadata && !metadata.nsfw;
|
||||||
autoplay && playingUri !== uri && metadata && !metadata.nsfw && !(uri in fileInfoErrors);
|
|
||||||
|
|
||||||
if (playable && costInfo && costInfo.cost === 0 && !fileInfo && !isDownloading) {
|
if (playable && costInfo && costInfo.cost === 0 && !fileInfo && !isDownloading) {
|
||||||
play(uri);
|
play(uri);
|
||||||
|
|
Loading…
Reference in a new issue